72 }} |
72 }} |
73 }} |
73 }} |
74 registerWebChannel(); |
74 registerWebChannel(); |
75 |
75 |
76 }})()""" |
76 }})()""" |
77 |
77 |
78 from WebBrowser.WebBrowserPage import WebBrowserPage |
78 from WebBrowser.WebBrowserPage import WebBrowserPage |
|
79 |
79 match = ( |
80 match = ( |
80 "// @exclude eric:*" |
81 "// @exclude eric:*" |
81 if worldId == WebBrowserPage.SafeJsWorld else |
82 if worldId == WebBrowserPage.SafeJsWorld |
82 "// @include eric:*" |
83 else "// @include eric:*" |
83 ) |
84 ) |
84 return source.format(match, getJavascript("qwebchannel.js")) |
85 return source.format(match, getJavascript("qwebchannel.js")) |
85 |
86 |
86 |
87 |
87 def setupWindowObject(): |
88 def setupWindowObject(): |
88 """ |
89 """ |
89 Function generating a script to setup window.object add-ons. |
90 Function generating a script to setup window.object add-ons. |
90 |
91 |
91 @return generated script |
92 @return generated script |
92 @rtype str |
93 @rtype str |
93 """ |
94 """ |
94 source = """ |
95 source = """ |
95 (function() { |
96 (function() { |
104 window.external = external; |
105 window.external = external; |
105 window.print = function() { |
106 window.print = function() { |
106 window.location = 'eric:PrintPage'; |
107 window.location = 'eric:PrintPage'; |
107 }; |
108 }; |
108 })()""" |
109 })()""" |
109 |
110 |
110 return source |
111 return source |
111 |
112 |
112 |
113 |
113 def setStyleSheet(css): |
114 def setStyleSheet(css): |
114 """ |
115 """ |
115 Function generating a script to set a user style sheet. |
116 Function generating a script to set a user style sheet. |
116 |
117 |
117 @param css style sheet to be applied |
118 @param css style sheet to be applied |
118 @type str |
119 @type str |
119 @return script to set a user style sheet |
120 @return script to set a user style sheet |
120 @rtype str |
121 @rtype str |
121 """ |
122 """ |
124 var css = document.createElement('style'); |
125 var css = document.createElement('style'); |
125 css.setAttribute('type', 'text/css'); |
126 css.setAttribute('type', 'text/css'); |
126 css.appendChild(document.createTextNode('{0}')); |
127 css.appendChild(document.createTextNode('{0}')); |
127 document.getElementsByTagName('head')[0].appendChild(css); |
128 document.getElementsByTagName('head')[0].appendChild(css); |
128 }})()""" |
129 }})()""" |
129 |
130 |
130 style = css.replace("'", "\\'").replace("\n", "\\n") |
131 style = css.replace("'", "\\'").replace("\n", "\\n") |
131 return source.format(style) |
132 return source.format(style) |
132 |
133 |
133 |
134 |
134 def getFormData(pos): |
135 def getFormData(pos): |
135 """ |
136 """ |
136 Function generating a script to extract data for a form element. |
137 Function generating a script to extract data for a form element. |
137 |
138 |
138 @param pos position to extract data at |
139 @param pos position to extract data at |
139 @type QPoint |
140 @type QPoint |
140 @return script to extract form data |
141 @return script to extract form data |
141 @rtype str |
142 @rtype str |
142 """ |
143 """ |
242 |
243 |
243 |
244 |
244 def sendPostData(url, data): |
245 def sendPostData(url, data): |
245 """ |
246 """ |
246 Function generating a script to send Post data. |
247 Function generating a script to send Post data. |
247 |
248 |
248 @param url URL to send the data to |
249 @param url URL to send the data to |
249 @type QUrl |
250 @type QUrl |
250 @param data data to be sent |
251 @param data data to be sent |
251 @type QByteArray |
252 @type QByteArray |
252 @return script to send Post data |
253 @return script to send Post data |
259 form.setAttribute('action', '{0}'); |
260 form.setAttribute('action', '{0}'); |
260 var val; |
261 var val; |
261 {1} |
262 {1} |
262 form.submit(); |
263 form.submit(); |
263 }})()""" |
264 }})()""" |
264 |
265 |
265 valueSource = """ |
266 valueSource = """ |
266 val = document.createElement('input'); |
267 val = document.createElement('input'); |
267 val.setAttribute('type', 'hidden'); |
268 val.setAttribute('type', 'hidden'); |
268 val.setAttribute('name', '{0}'); |
269 val.setAttribute('name', '{0}'); |
269 val.setAttribute('value', '{1}'); |
270 val.setAttribute('value', '{1}'); |
270 form.appendChild(val);""" |
271 form.appendChild(val);""" |
271 |
272 |
272 values = "" |
273 values = "" |
273 query = QUrlQuery(data) |
274 query = QUrlQuery(data) |
274 for name, value in query.queryItems( |
275 for name, value in query.queryItems(QUrl.ComponentFormattingOption.FullyDecoded): |
275 QUrl.ComponentFormattingOption.FullyDecoded |
|
276 ): |
|
277 value = value.replace("'", "\\'") |
276 value = value.replace("'", "\\'") |
278 name = name.replace("'", "\\'") |
277 name = name.replace("'", "\\'") |
279 values += valueSource.format(name, value) |
278 values += valueSource.format(name, value) |
280 |
279 |
281 return source.format(url.toString(), values) |
280 return source.format(url.toString(), values) |
282 |
281 |
283 |
282 |
284 def setupFormObserver(): |
283 def setupFormObserver(): |
285 """ |
284 """ |
286 Function generating a script to monitor a web form for user entries. |
285 Function generating a script to monitor a web form for user entries. |
287 |
286 |
288 @return script to monitor a web page |
287 @return script to monitor a web page |
289 @rtype str |
288 @rtype str |
290 """ |
289 """ |
291 source = """ |
290 source = """ |
292 (function() { |
291 (function() { |
386 }} |
385 }} |
387 }} |
386 }} |
388 }} |
387 }} |
389 |
388 |
390 }})()""" |
389 }})()""" |
391 |
390 |
392 data = bytes(data).decode("utf-8") |
391 data = bytes(data).decode("utf-8") |
393 data = data.replace("'", "\\'") |
392 data = data.replace("'", "\\'") |
394 return source.format(data) |
393 return source.format(data) |
395 |
394 |
396 |
395 |
397 def setCss(css): |
396 def setCss(css): |
398 """ |
397 """ |
399 Function generating a script to set a given CSS style sheet. |
398 Function generating a script to set a given CSS style sheet. |
400 |
399 |
401 @param css style sheet |
400 @param css style sheet |
402 @type str |
401 @type str |
403 @return script to set the style sheet |
402 @return script to set the style sheet |
404 @rtype str |
403 @rtype str |
405 """ |
404 """ |
434 if (e) |
433 if (e) |
435 e.scrollIntoView() |
434 e.scrollIntoView() |
436 }})()""" |
435 }})()""" |
437 return source.format(anchor) |
436 return source.format(anchor) |
438 |
437 |
|
438 |
439 ########################################################################### |
439 ########################################################################### |
440 ## scripts below are specific for eric |
440 ## scripts below are specific for eric |
441 ########################################################################### |
441 ########################################################################### |
442 |
442 |
443 |
443 |
444 def getFeedLinks(): |
444 def getFeedLinks(): |
445 """ |
445 """ |
446 Function generating a script to extract all RSS and Atom feed links. |
446 Function generating a script to extract all RSS and Atom feed links. |
447 |
447 |
448 @return script to extract all RSS and Atom feed links |
448 @return script to extract all RSS and Atom feed links |
449 @rtype str |
449 @rtype str |
450 """ |
450 """ |
451 source = """ |
451 source = """ |
452 (function() { |
452 (function() { |