eric6/WebBrowser/GreaseMonkey/GreaseMonkeyJavaScript.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7360
9190402e4505
permissions
-rw-r--r--

Updated copyright for 2021.

1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
3 # Copyright (c) 2012 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module containing some JavaScript resources.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
10
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 bootstrap_js = """
6128
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
12 var GM = {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
13 info: {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
14 script: {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
15 description: "",
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
16 excludes: [],
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
17 includes: [],
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
18 matches: [],
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
19 name: "",
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
20 namespace: "",
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
21 resources: {},
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
22 'run-at': "document-end",
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
23 version: ""
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
24 },
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
25 scriptMetaStr: "",
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
26 scriptHandler: "eric Browser GreaseMonkey",
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
27 version: "4.0"
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
28 }
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
29 };
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
30 window.GM = GM;
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
6128
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
32 function GM_info() {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
33 return GM.info;
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
34 }
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
35
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
36 function GM_xmlhttpRequest(/* object */ details) {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
37 details.method = details.method.toUpperCase() || "GET";
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
38
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
39 if (!details.url) {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
40 throw("GM_xmlhttpRequest requires an URL.");
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
41 }
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
6128
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
43 // build XMLHttpRequest object
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
44 var oXhr = new XMLHttpRequest;
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
45 // run it
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
46 if("onreadystatechange" in details)
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
47 oXhr.onreadystatechange = function() {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
48 details.onreadystatechange(oXhr) };
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
49 if("onload" in details)
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
50 oXhr.onload = function() { details.onload(oXhr) };
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
51 if("onerror" in details)
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
52 oXhr.onerror = function() { details.onerror(oXhr) };
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
53
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
54 oXhr.open(details.method, details.url, true);
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
55
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
56 if("headers" in details)
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
57 for(var header in details.headers)
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
58 oXhr.setRequestHeader(header, details.headers[header]);
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
6128
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
60 if("data" in details)
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
61 oXhr.send(details.data);
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
62 else
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
63 oXhr.send();
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
64 }
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65
6128
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
66 function GM_addStyle(/* string */ styles) {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
67 var head = document.getElementsByTagName("head")[0];
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
68 if (head === undefined) {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
69 document.onreadystatechange = function() {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
70 if (document.readyState == "interactive") {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
71 var oStyle = document.createElement("style");
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
72 oStyle.setAttribute("type", "text/css");
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
73 oStyle.appendChild(document.createTextNode(styles));
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
74 document.getElementsByTagName("head")[0].appendChild(oStyle);
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
75 }
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
76 }
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
77 }
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
78 else {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
79 var oStyle = document.createElement("style");
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
80 oStyle.setAttribute("type", "text/css");
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
81 oStyle.appendChild(document.createTextNode(styles));
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
82 head.appendChild(oStyle);
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 }
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 }
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85
6128
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
86 function GM_log(log) {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
87 if(console)
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
88 console.log(log);
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 }
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
6128
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
91 function GM_openInTab(url) {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
92 return window.open(url);
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 }
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94
6128
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
95 function GM_setClipboard(text) {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
96 external.extra.greasemonkey.setClipboard(text);
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 }
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98
6128
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
99 // GM_registerMenuCommand not supported
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
100 function GM_registerMenuCommand(caption, commandFunc, accessKey) { }
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
6128
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
102 // GM_getResourceUrl not supported
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
103 function GM_getResourceUrl(resourceName) { }
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104
6128
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
105 // GreaseMonkey 4.0 support
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
106 GM.openInTab = GM_openInTab;
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
107 GM.setClipboard = GM_setClipboard;
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
108 GM.xmlhttpRequest = GM_xmlhttpRequest;
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109
6128
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
110 // GM_getResourceUrl not supported
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
111 GM.getResourceUrl = function(resourceName) {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
112 return new Promise((resolve, reject) => {
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
113 reject();
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
114 });
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
115 };
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 """
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
117
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
118
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
119 # {0} - unique script id
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
120 values_js = """
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
121 function GM_deleteValue(aKey) {{
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
122 localStorage.removeItem("{0}" + aKey);
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
123 }}
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
124
4886
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
125 function GM_getValue(aKey, aDefault) {{
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
126 var val = localStorage.getItem("{0}" + aKey)
6326
5ef9456a0cbe WebBrowser: Some little changes to increase stability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6128
diff changeset
127 if (null === val) return aDefault;
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
128 return val;
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
129 }}
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
130
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
131 function GM_listValues() {{
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
132 var values = [];
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
133 for (var i = 0; i < localStorage.length; i++) {{
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
134 var k = localStorage.key(i);
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
135 if (k.indexOf("{0}") === 0) {{
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
136 values.push(k.replace("{0}", ""));
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
137 }}
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
138 }}
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
139 return values;
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
140 }}
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
141
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
142 function GM_setValue(aKey, aVal) {{
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
143 localStorage.setItem("{0}" + aKey, aVal);
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
144 }}
6128
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
145
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
146 // GreaseMonkey 4.0 support
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
147 var asyncCall = (func) => {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
148 if (window._eric_external) {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
149 func();
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
150 }} else {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
151 document.addEventListener("_eric_external_created", func);
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
152 }}
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
153 }};
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
154
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
155 var decode = (val) => {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
156 val = String(val);
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
157 if (!val.length) {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
158 return val;
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
159 }}
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
160 var v = val.substr(1);
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
161 if (val[0] == "b") {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
162 return Boolean(v == "true" ? true : false);
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
163 }} else if (val[0] == "i") {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
164 return Number(v);
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
165 }} else if (val[0] == "s") {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
166 return v;
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
167 }} else {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
168 return undefined;
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
169 }}
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
170 }};
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
171
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
172 var encode = (val) => {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
173 if (typeof val == "boolean") {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
174 return "b" + (val ? "true" : "false");
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
175 }} else if (typeof val == "number") {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
176 return "i" + String(val);
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
177 }} else if (typeof val == "string") {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
178 return "s" + val;
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
179 }} else {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
180 return "";
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
181 }}
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
182 }};
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
183
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
184 GM.deleteValue = function(name) {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
185 return new Promise((resolve, reject) => {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
186 asyncCall(() => {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
187 external.extra.greasemonkey.deleteValue("{0}", name, (res) => {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
188 if (res) {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
189 resolve();
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
190 }} else {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
191 reject();
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
192 }}
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
193 }});
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
194 }});
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
195 }});
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
196 }};
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
197
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
198 GM.getValue = function(name, value) {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
199 return new Promise((resolve) => {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
200 asyncCall(() => {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
201 external.extra.greasemonkey.getValue("{0}", name, encode(value),
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
202 (res) => {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
203 resolve(decode(res));
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
204 }});
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
205 }});
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
206 }});
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
207 }};
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
208
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
209 GM.setValue = function(name, value) {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
210 return new Promise((resolve, reject) => {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
211 asyncCall(() => {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
212 external.extra.greasemonkey.setValue("{0}", name, encode(value),
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
213 (res) => {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
214 if (res) {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
215 resolve();
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
216 }} else {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
217 reject();
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
218 }}
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
219 }});
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
220 }});
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
221 }});
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
222 }};
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
223
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
224 GM.listValues = function() {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
225 return new Promise((resolve) => {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
226 asyncCall(() => {{
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
227 external.extra.greasemonkey.listValues("{0}", resolve);
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
228 }});
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
229 }});
afc2cda1a743 Implemented support for GreaseMonkey 4.0 for the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
230 }};
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
231 """

eric ide

mercurial