eric6/WebBrowser/Tools/Scripts.py

Sat, 10 Apr 2021 18:38:27 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 10 Apr 2021 18:38:27 +0200
changeset 8218
7c09585bd960
parent 8143
2c730d5fd177
child 8260
2161475d9639
permissions
-rw-r--r--

Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).

4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2016 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module containing function to generate JavaScript code.
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
10 #
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
11 # This code was ported from QupZilla.
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
12 # Copyright (C) David Rosca <nowrep@gmail.com>
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
13 #
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
14
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
15 from PyQt5.QtCore import QUrlQuery, QUrl
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
16
7717
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
17 from .WebBrowserTools import getJavascript
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6135
diff changeset
20 def setupWebChannel(worldId):
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Function generating a script to setup the web channel.
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
6149
e611e45a17d6 Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
24 @param worldId world ID for which to setup the channel
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6135
diff changeset
25 @type int
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @return script to setup the web channel
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @rtype str
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 source = """
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6135
diff changeset
30 // ==UserScript==
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6135
diff changeset
31 {0}
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6135
diff changeset
32 // ==/UserScript==
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6135
diff changeset
33
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
34 (function() {{
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6135
diff changeset
35 {1}
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
36
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
37 function registerExternal(e) {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
38 window.external = e;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
39 if (window.external) {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
40 var event = document.createEvent('Event');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
41 event.initEvent('_eric_external_created', true, true);
6129
049ab6ad3144 Some more GreaseMonkey changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
42 window._eric_external = true;
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
43 document.dispatchEvent(event);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
44 }}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
45 }}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
46
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
47 if (self !== top) {{
6129
049ab6ad3144 Some more GreaseMonkey changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
48 if (top._eric_external)
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
49 registerExternal(top.external);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
50 else
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
51 top.document.addEventListener(
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
52 '_eric_external_created', function() {{
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 registerExternal(top.external);
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
54 }});
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
55 return;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
56 }}
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
58 function registerWebChannel() {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
59 try {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
60 new QWebChannel(qt.webChannelTransport, function(channel) {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
61 var external = channel.objects.eric_object;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
62 external.extra = {{}};
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
63 for (var key in channel.objects) {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
64 if (key != 'eric_object' && key.startsWith('eric_')) {{
6135
12e48d27f1d7 Fixed a few issue introduced by the recent changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6129
diff changeset
65 external.extra[key.substr(5)] = channel.objects[key];
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
66 }}
5342
2b6821805f46 Fixed creating the web channel in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
67 }}
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
68 registerExternal(external);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
69 }});
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
70 }} catch (e) {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
71 setTimeout(registerWebChannel, 100);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
72 }}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
73 }}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
74 registerWebChannel();
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
76 }})()"""
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6135
diff changeset
78 from WebBrowser.WebBrowserPage import WebBrowserPage
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6135
diff changeset
79 if worldId == WebBrowserPage.SafeJsWorld:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6135
diff changeset
80 match = "// @exclude eric:*"
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6135
diff changeset
81 else:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6135
diff changeset
82 match = "// @include eric:*"
7717
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
83 return source.format(match, getJavascript("qwebchannel.js"))
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85
6142
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
86 def setupWindowObject():
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
87 """
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
88 Function generating a script to setup window.object add-ons.
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
89
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
90 @return generated script
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
91 @rtype str
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
92 """
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
93 source = """
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
94 (function() {
6174
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
95 var external = {};
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
96 external.AddSearchProvider = function(url) {
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
97 window.location = 'eric:AddSearchProvider?url=' + url;
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
98 };
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
99 external.IsSearchProviderInstalled = function(url) {
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
100 console.warn('NOT IMPLEMENTED: IsSearchProviderInstalled()');
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
101 return false;
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
102 };
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
103 window.external = external;
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
104 window.print = function() {
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
105 window.location = 'eric:PrintPage';
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
106 };
6142
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
107 })()"""
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
108
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
109 return source
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
110
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
111
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 def setStyleSheet(css):
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 Function generating a script to set a user style sheet.
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
116 @param css style sheet to be applied
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
117 @type str
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 @return script to set a user style sheet
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 @rtype str
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
122 (function() {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
123 var css = document.createElement('style');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
124 css.setAttribute('type', 'text/css');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
125 css.appendChild(document.createTextNode('{0}'));
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
126 document.getElementsByTagName('head')[0].appendChild(css);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
127 }})()"""
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 style = css.replace("'", "\\'").replace("\n", "\\n")
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 return source.format(style)
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
131
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
132
4731
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
133 def getFormData(pos):
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
134 """
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
135 Function generating a script to extract data for a form element.
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
136
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
137 @param pos position to extract data at
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
138 @type QPoint
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
139 @return script to extract form data
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
140 @rtype str
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
141 """
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
142 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
143 (function() {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
144 var e = document.elementFromPoint({0}, {1});
6174
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
145 if (!e || e.tagName.toLowerCase() != 'input')
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
146 return;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
147 var fe = e.parentElement;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
148 while (fe) {{
6174
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
149 if (fe.tagName.toLowerCase() != 'form')
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
150 break;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
151 fe = fe.parentElement;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
152 }}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
153 if (!fe)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
154 return;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
155 var res = {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
156 method: fe.method.toLowerCase(),
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
157 action: fe.action,
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
158 inputName: e.name,
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
159 inputs: [],
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
160 }};
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
161 for (var i = 0; i < fe.length; ++i) {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
162 var input = fe.elements[i];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
163 res.inputs.push([input.name, input.value]);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
164 }}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
165 return res;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
166 }})()"""
4731
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
167 return source.format(pos.x(), pos.y())
4733
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
168
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
169
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
170 def getAllImages():
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
171 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
172 Function generating a script to extract all image tags of a web page.
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
173
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
174 @return script to extract image tags
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
175 @rtype str
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
176 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
177 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
178 (function() {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
179 var out = [];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
180 var imgs = document.getElementsByTagName('img');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
181 for (var i = 0; i < imgs.length; ++i) {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
182 var e = imgs[i];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
183 out.push({
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
184 src: e.src,
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
185 alt: e.alt
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
186 });
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
187 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
188 return out;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
189 })()"""
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
190 return source
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
191
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
192
4733
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
193 def getAllMetaAttributes():
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
194 """
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
195 Function generating a script to extract all meta attributes of a web page.
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
196
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
197 @return script to extract meta attributes
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
198 @rtype str
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
199 """
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
200 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
201 (function() {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
202 var out = [];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
203 var meta = document.getElementsByTagName('meta');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
204 for (var i = 0; i < meta.length; ++i) {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
205 var e = meta[i];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
206 out.push({
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
207 name: e.getAttribute('name'),
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
208 content: e.getAttribute('content'),
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
209 httpequiv: e.getAttribute('http-equiv'),
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
210 charset: e.getAttribute('charset')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
211 });
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
212 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
213 return out;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
214 })()"""
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
215 return source
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
216
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
217
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
218 def getOpenSearchLinks():
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
219 """
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
220 Function generating a script to extract all open search links.
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
221
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
222 @return script to extract all open serach links
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
223 @rtype str
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
224 """
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
225 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
226 (function() {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
227 var out = [];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
228 var links = document.getElementsByTagName('link');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
229 for (var i = 0; i < links.length; ++i) {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
230 var e = links[i];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
231 if (e.type == 'application/opensearchdescription+xml') {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
232 out.push({
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
233 url: e.getAttribute('href'),
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
234 title: e.getAttribute('title')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
235 });
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
236 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
237 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
238 return out;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
239 })()"""
4733
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
240 return source
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
241
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
242
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
243 def sendPostData(url, data):
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
244 """
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
245 Function generating a script to send Post data.
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
246
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
247 @param url URL to send the data to
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
248 @type QUrl
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
249 @param data data to be sent
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
250 @type QByteArray
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
251 @return script to send Post data
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
252 @rtype str
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
253 """
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
254 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
255 (function() {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
256 var form = document.createElement('form');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
257 form.setAttribute('method', 'POST');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
258 form.setAttribute('action', '{0}');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
259 var val;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
260 {1}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
261 form.submit();
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
262 }})()"""
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
263
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
264 valueSource = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
265 val = document.createElement('input');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
266 val.setAttribute('type', 'hidden');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
267 val.setAttribute('name', '{0}');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
268 val.setAttribute('value', '{1}');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
269 form.appendChild(val);"""
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
270
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
271 values = ""
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
272 query = QUrlQuery(data)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
273 for name, value in query.queryItems(
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
274 QUrl.ComponentFormattingOption.FullyDecoded
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
275 ):
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
276 value = value.replace("'", "\\'")
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
277 name = name.replace("'", "\\'")
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
278 values += valueSource.format(name, value)
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
279
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
280 return source.format(url.toString(), values)
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
281
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
282
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
283 def setupFormObserver():
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
284 """
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
285 Function generating a script to monitor a web form for user entries.
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
286
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
287 @return script to monitor a web page
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
288 @rtype str
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
289 """
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
290 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
291 (function() {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
292 function findUsername(inputs) {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
293 var usernameNames = ['user', 'name', 'login'];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
294 for (var i = 0; i < usernameNames.length; ++i) {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
295 for (var j = 0; j < inputs.length; ++j)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
296 if (inputs[j].type == 'text' &&
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
297 inputs[j].value.length &&
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
298 inputs[j].name.indexOf(usernameNames[i]) != -1)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
299 return inputs[j].value;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
300 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
301 for (var i = 0; i < inputs.length; ++i)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
302 if (inputs[i].type == 'text' && inputs[i].value.length)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
303 return inputs[i].value;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
304 for (var i = 0; i < inputs.length; ++i)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
305 if (inputs[i].type == 'email' && inputs[i].value.length)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
306 return inputs[i].value;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
307 return '';
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
308 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
309
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
310 function registerForm(form) {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
311 form.addEventListener('submit', function() {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
312 var form = this;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
313 var data = '';
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
314 var password = '';
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
315 var inputs = form.getElementsByTagName('input');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
316 for (var i = 0; i < inputs.length; ++i) {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
317 var input = inputs[i];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
318 var type = input.type.toLowerCase();
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
319 if (type != 'text' && type != 'password' &&
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
320 type != 'email')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
321 continue;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
322 if (!password && type == 'password')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
323 password = input.value;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
324 data += encodeURIComponent(input.name);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
325 data += '=';
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
326 data += encodeURIComponent(input.value);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
327 data += '&';
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
328 }
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
329 if (!password)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
330 return;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
331 data = data.substring(0, data.length - 1);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
332 var url = window.location.href;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
333 var username = findUsername(inputs);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
334 external.passwordManager.formSubmitted(
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
335 url, username, password, data);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
336 }, true);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
337 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
338
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
339 for (var i = 0; i < document.forms.length; ++i)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
340 registerForm(document.forms[i]);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
341
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
342 var observer = new MutationObserver(function(mutations) {
6174
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
343 for (var mutation of mutations)
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
344 for (var node of mutation.addedNodes)
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
345 if (node.tagName && node.tagName.toLowerCase() == 'form')
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
346 registerForm(node);
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
347 });
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
348 observer.observe(document.documentElement, {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
349 childList: true, subtree: true
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
350 });
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
351
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
352 })()"""
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
353 return source
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
354
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
355
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
356 def completeFormData(data):
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
357 """
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
358 Function generating a script to fill in form data.
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
359
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
360 @param data data to be filled into the form
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
361 @type QByteArray
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
362 @return script to fill a form
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
363 @rtype str
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
364 """
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
365 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
366 (function() {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
367 var data = '{0}'.split('&');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
368 var inputs = document.getElementsByTagName('input');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
369
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
370 for (var i = 0; i < data.length; ++i) {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
371 var pair = data[i].split('=');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
372 if (pair.length != 2)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
373 continue;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
374 var key = decodeURIComponent(pair[0]);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
375 var val = decodeURIComponent(pair[1]);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
376 for (var j = 0; j < inputs.length; ++j) {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
377 var input = inputs[j];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
378 var type = input.type.toLowerCase();
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
379 if (type != 'text' && type != 'password' &&
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
380 type != 'email')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
381 continue;
6174
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
382 if (input.name == key) {{
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
383 input.value = val;
6174
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
384 input.dispatchEvent(new Event('change'));
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
385 }}
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
386 }}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
387 }}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
388
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
389 }})()"""
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
390
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
391 data = bytes(data).decode("utf-8")
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
392 data = data.replace("'", "\\'")
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
393 return source.format(data)
4758
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
394
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
395
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
396 def setCss(css):
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
397 """
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
398 Function generating a script to set a given CSS style sheet.
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
399
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
400 @param css style sheet
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
401 @type str
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
402 @return script to set the style sheet
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
403 @rtype str
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
404 """
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
405 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
406 (function() {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
407 var css = document.createElement('style');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
408 css.setAttribute('type', 'text/css');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
409 css.appendChild(document.createTextNode('{0}'));
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
410 document.getElementsByTagName('head')[0].appendChild(css);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
411 }})()"""
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
412 style = css.replace("'", "\\'").replace("\n", "\\n")
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
413 return source.format(style)
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
414
6692
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
415
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
416 def scrollToAnchor(anchor):
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
417 """
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
418 Function generating script to scroll to a given anchor.
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
419
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
420 @param anchor name of the anchor to scroll to
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
421 @type str
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
422 @return script to set the style sheet
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
423 @rtype str
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
424 """
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
425 source = """
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
426 (function() {{
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
427 var e = document.getElementById("{0}")
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
428 if (!e) {{
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
429 var els = document.querySelectorAll("[name='{0}']");
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
430 if (els.length)
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
431 e = els[0]
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
432 }}
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
433 if (e)
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
434 e.scrollIntoView()
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
435 }})()"""
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
436 return source.format(anchor)
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
437
4758
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
438 ###########################################################################
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
439 ## scripts below are specific for eric
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
440 ###########################################################################
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
441
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
442
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
443 def getFeedLinks():
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
444 """
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
445 Function generating a script to extract all RSS and Atom feed links.
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
446
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
447 @return script to extract all RSS and Atom feed links
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
448 @rtype str
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
449 """
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
450 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
451 (function() {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
452 var out = [];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
453 var links = document.getElementsByTagName('link');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
454 for (var i = 0; i < links.length; ++i) {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
455 var e = links[i];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
456 if ((e.rel == 'alternate') &&
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
457 ((e.type == 'application/atom+xml') ||
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
458 (e.type == 'application/rss+xml')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
459 )
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
460 ) {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
461 out.push({
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
462 url: e.getAttribute('href'),
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
463 title: e.getAttribute('title')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
464 });
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
465 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
466 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
467 return out;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
468 })()"""
4758
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
469 return source

eric ide

mercurial