WebBrowser/Tools/Scripts.py

Sun, 11 Feb 2018 18:21:11 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 11 Feb 2018 18:21:11 +0100
changeset 6135
12e48d27f1d7
parent 6129
049ab6ad3144
child 6140
c20e2d414d0d
permissions
-rw-r--r--

Fixed a few issue introduced by the recent changes.

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
6048
82ad8ec9548c Updated copyright for 2018.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5747
diff changeset
3 # Copyright (c) 2016 - 2018 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
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from __future__ import unicode_literals
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
17 from PyQt5.QtCore import QUrlQuery, QUrl
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
18
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from .WebBrowserTools import readAllFileContents
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
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 def setupWebChannel():
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 Function generating a script to setup the web channel.
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
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 = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
30 (function() {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
31 {0}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
32
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
33 function registerExternal(e) {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
34 window.external = e;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
35 if (window.external) {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
36 var event = document.createEvent('Event');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
37 event.initEvent('_eric_external_created', true, true);
6129
049ab6ad3144 Some more GreaseMonkey changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
38 window._eric_external = true;
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
39 document.dispatchEvent(event);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
40 }}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
41 }}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
42
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
43 if (self !== top) {{
6129
049ab6ad3144 Some more GreaseMonkey changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
44 if (top._eric_external)
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
45 registerExternal(top.external);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
46 else
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
47 top.document.addEventListener(
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
48 '_eric_external_created', function() {{
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 registerExternal(top.external);
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
50 }});
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
51 return;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
52 }}
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
54 function registerWebChannel() {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
55 try {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
56 new QWebChannel(qt.webChannelTransport, function(channel) {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
57 var external = channel.objects.eric_object;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
58 external.extra = {{}};
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
59 for (var key in channel.objects) {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
60 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
61 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
62 }}
5342
2b6821805f46 Fixed creating the web channel in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
63 }}
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
64 registerExternal(external);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
65 }});
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
66 }} catch (e) {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
67 setTimeout(registerWebChannel, 100);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
68 }}
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 registerWebChannel();
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
72 }})()"""
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 return source.format(readAllFileContents(":/javascript/qwebchannel.js"))
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 def setStyleSheet(css):
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 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
80
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
81 @param css style sheet to be applied
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
82 @type str
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 @return script to set a user style sheet
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 @rtype str
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
87 (function() {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
88 var css = document.createElement('style');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
89 css.setAttribute('type', 'text/css');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
90 css.appendChild(document.createTextNode('{0}'));
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
91 document.getElementsByTagName('head')[0].appendChild(css);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
92 }})()"""
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 style = css.replace("'", "\\'").replace("\n", "\\n")
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 return source.format(style)
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
96
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
97
4731
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
98 def getFormData(pos):
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
99 """
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
100 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
101
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
102 @param pos position to extract data at
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
103 @type QPoint
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
104 @return script to extract form data
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
105 @rtype str
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
106 """
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
107 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
108 (function() {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
109 var e = document.elementFromPoint({0}, {1});
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
110 if (!e || e.tagName != 'INPUT')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
111 return;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
112 var fe = e.parentElement;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
113 while (fe) {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
114 if (fe.tagName == 'FORM')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
115 break;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
116 fe = fe.parentElement;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
117 }}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
118 if (!fe)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
119 return;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
120 var res = {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
121 method: fe.method.toLowerCase(),
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
122 action: fe.action,
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
123 inputName: e.name,
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
124 inputs: [],
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
125 }};
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
126 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
127 var input = fe.elements[i];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
128 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
129 }}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
130 return res;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
131 }})()"""
4731
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
132 return source.format(pos.x(), pos.y())
4733
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
133
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
134
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
135 def getAllImages():
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
136 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
137 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
138
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
139 @return script to extract image tags
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
140 @rtype str
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
141 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
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 out = [];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
145 var imgs = document.getElementsByTagName('img');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
146 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
147 var e = imgs[i];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
148 out.push({
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
149 src: e.src,
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
150 alt: e.alt
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
151 });
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 return out;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
154 })()"""
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
155 return source
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
156
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
157
4733
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
158 def getAllMetaAttributes():
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
159 """
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
160 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
161
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
162 @return script to extract meta attributes
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
163 @rtype str
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
164 """
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
165 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
166 (function() {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
167 var out = [];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
168 var meta = document.getElementsByTagName('meta');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
169 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
170 var e = meta[i];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
171 out.push({
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
172 name: e.getAttribute('name'),
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
173 content: e.getAttribute('content'),
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
174 httpequiv: e.getAttribute('http-equiv'),
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
175 charset: e.getAttribute('charset')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
176 });
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
177 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
178 return out;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
179 })()"""
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
180 return source
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
181
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
182
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
183 def getOpenSearchLinks():
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
184 """
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
185 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
186
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
187 @return script to extract all open serach links
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
188 @rtype str
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
189 """
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
190 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
191 (function() {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
192 var out = [];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
193 var links = document.getElementsByTagName('link');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
194 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
195 var e = links[i];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
196 if (e.type == 'application/opensearchdescription+xml') {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
197 out.push({
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
198 url: e.getAttribute('href'),
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
199 title: e.getAttribute('title')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
200 });
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
201 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
202 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
203 return out;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
204 })()"""
4733
ae291a307ea6 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
205 return source
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
206
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
207
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
208 def sendPostData(url, data):
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
209 """
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
210 Function generating a script to send Post data.
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
211
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
212 @param url URL to send the data to
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
213 @type QUrl
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
214 @param data data to be sent
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
215 @type QByteArray
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
216 @return script to send Post data
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
217 @rtype str
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
218 """
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
219 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
220 (function() {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
221 var form = document.createElement('form');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
222 form.setAttribute('method', 'POST');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
223 form.setAttribute('action', '{0}');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
224 var val;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
225 {1}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
226 form.submit();
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
227 }})()"""
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
228
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
229 valueSource = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
230 val = document.createElement('input');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
231 val.setAttribute('type', 'hidden');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
232 val.setAttribute('name', '{0}');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
233 val.setAttribute('value', '{1}');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
234 form.appendChild(val);"""
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
235
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
236 values = ""
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
237 query = QUrlQuery(data)
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
238 for name, value in query.queryItems(QUrl.FullyDecoded):
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
239 value = value.replace("'", "\\'")
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
240 name = name.replace("'", "\\'")
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4733
diff changeset
241 values += valueSource.format(name, value)
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 return source.format(url.toString(), values)
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
244
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
245
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
246 def setupFormObserver():
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
247 """
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
248 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
249
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
250 @return script to monitor a web page
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
251 @rtype str
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
252 """
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
253 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
254 (function() {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
255 function findUsername(inputs) {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
256 var usernameNames = ['user', 'name', 'login'];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
257 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
258 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
259 if (inputs[j].type == 'text' &&
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
260 inputs[j].value.length &&
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
261 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
262 return inputs[j].value;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
263 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
264 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
265 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
266 return inputs[i].value;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
267 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
268 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
269 return inputs[i].value;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
270 return '';
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
271 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
272
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
273 function registerForm(form) {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
274 form.addEventListener('submit', function() {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
275 var form = this;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
276 var data = '';
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
277 var password = '';
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
278 var inputs = form.getElementsByTagName('input');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
279 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
280 var input = inputs[i];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
281 var type = input.type.toLowerCase();
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
282 if (type != 'text' && type != 'password' &&
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
283 type != 'email')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
284 continue;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
285 if (!password && type == 'password')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
286 password = input.value;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
287 data += encodeURIComponent(input.name);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
288 data += '=';
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
289 data += encodeURIComponent(input.value);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
290 data += '&';
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
291 }
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
292 if (!password)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
293 return;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
294 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
295 var url = window.location.href;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
296 var username = findUsername(inputs);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
297 external.passwordManager.formSubmitted(
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
298 url, username, password, data);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
299 }, true);
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
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
302 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
303 registerForm(document.forms[i]);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
304
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
305 var observer = new MutationObserver(function(mutations) {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
306 for (var i = 0; i < mutations.length; ++i)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
307 for (var j = 0; j < mutations[i].addedNodes.length; ++j)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
308 if (mutations[i].addedNodes[j].tagName == 'FORM')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
309 registerForm(mutations[i].addedNodes[j]);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
310 });
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
311 observer.observe(document.documentElement, {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
312 childList: true, subtree: true
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
313 });
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
314
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
315 })()"""
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
316 return source
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
317
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
318
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
319 def completeFormData(data):
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
320 """
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
321 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
322
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
323 @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
324 @type QByteArray
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
325 @return script to fill a form
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
326 @rtype str
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
327 """
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
328 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
329 (function() {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
330 var data = '{0}'.split('&');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
331 var inputs = document.getElementsByTagName('input');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
332
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
333 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
334 var pair = data[i].split('=');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
335 if (pair.length != 2)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
336 continue;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
337 var key = decodeURIComponent(pair[0]);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
338 var val = decodeURIComponent(pair[1]);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
339 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
340 var input = inputs[j];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
341 var type = input.type.toLowerCase();
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
342 if (type != 'text' && type != 'password' &&
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
343 type != 'email')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
344 continue;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
345 if (input.name == key)
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
346 input.value = val;
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 }}
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
349
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
350 }})()"""
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
351
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
352 data = bytes(data).decode("utf-8")
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
353 data = data.replace("'", "\\'")
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
354 return source.format(data)
4758
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
355
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
356
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
357 def setCss(css):
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
358 """
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
359 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
360
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
361 @param css style sheet
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
362 @type str
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
363 @return script to set the style sheet
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
364 @rtype str
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
365 """
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
366 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
367 (function() {{
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
368 var css = document.createElement('style');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
369 css.setAttribute('type', 'text/css');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
370 css.appendChild(document.createTextNode('{0}'));
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
371 document.getElementsByTagName('head')[0].appendChild(css);
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
372 }})()"""
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
373 style = css.replace("'", "\\'").replace("\n", "\\n")
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
374 return source.format(style)
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
375
4758
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
376 ###########################################################################
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
377 ## scripts below are specific for eric
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
378 ###########################################################################
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
379
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
380
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
381 def getFeedLinks():
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
382 """
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
383 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
384
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
385 @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
386 @rtype str
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
387 """
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
388 source = """
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
389 (function() {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
390 var out = [];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
391 var links = document.getElementsByTagName('link');
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
392 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
393 var e = links[i];
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
394 if ((e.rel == 'alternate') &&
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
395 ((e.type == 'application/atom+xml') ||
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
396 (e.type == 'application/rss+xml')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
397 )
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
398 ) {
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
399 out.push({
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
400 url: e.getAttribute('href'),
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
401 title: e.getAttribute('title')
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
402 });
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
403 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
404 }
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
405 return out;
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
406 })()"""
4758
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
407 return source

eric ide

mercurial