eric6/Helpviewer/GreaseMonkey/GreaseMonkeyJavaScript.py

branch
maintenance
changeset 7286
7eb04391adf7
parent 7226
babe80d84a3e
parent 7285
1ff497f33f31
child 7287
1c17f2191bdd
equal deleted inserted replaced
7226:babe80d84a3e 7286:7eb04391adf7
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2012 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module containing some JavaScript resources.
8 """
9
10 from __future__ import unicode_literals
11
12 bootstrap_js = """
13 if(typeof GM_xmlhttpRequest === "undefined") {
14 GM_xmlhttpRequest = function(/* object */ details) {
15 details.method = details.method.toUpperCase() || "GET";
16
17 if(!details.url) {
18 throw("GM_xmlhttpRequest requires an URL.");
19 }
20
21 // build XMLHttpRequest object
22 var oXhr = new XMLHttpRequest;
23 // run it
24 if(oXhr) {
25 if("onreadystatechange" in details)
26 oXhr.onreadystatechange = function() {
27 details.onreadystatechange(oXhr)
28 };
29 if("onload" in details)
30 oXhr.onload = function() { details.onload(oXhr) };
31 if("onerror" in details)
32 oXhr.onerror = function() { details.onerror(oXhr) };
33
34 oXhr.open(details.method, details.url, true);
35
36 if("headers" in details)
37 for(var header in details.headers)
38 oXhr.setRequestHeader(header, details.headers[header]);
39
40 if("data" in details)
41 oXhr.send(details.data);
42 else
43 oXhr.send();
44 } else
45 throw ("This Browser is not supported, please upgrade.")
46 }
47 }
48
49 if(typeof GM_addStyle === "undefined") {
50 function GM_addStyle(/* String */ styles) {
51 var head = document.getElementsByTagName("head")[0];
52 if (head === undefined) {
53 document.onreadystatechange = function() {
54 if (document.readyState == "interactive") {
55 var oStyle = document.createElement("style");
56 oStyle.setAttribute("type", "text/css");
57 oStyle.appendChild(document.createTextNode(styles));
58 document.getElementsByTagName("head")[0].appendChild(oStyle);
59 }
60 }
61 }
62 else {
63 var oStyle = document.createElement("style");
64 oStyle.setAttribute("type", "text/css");
65 oStyle.appendChild(document.createTextNode(styles));
66 head.appendChild(oStyle);
67 }
68 }
69 }
70
71 if(typeof GM_log === "undefined") {
72 function GM_log(log) {
73 if(console)
74 console.log(log);
75 }
76 }
77
78 if(typeof GM_openInTab === "undefined") {
79 function GM_openInTab(url) {
80 window.open(url)
81 }
82 }
83
84 // Define unsafe window
85 var unsafeWindow = window;
86 window.wrappedJSObject = unsafeWindow;
87
88 // GM_registerMenuCommand not supported
89 if(typeof GM_registerMenuCommand === "undefined") {
90 function GM_registerMenuCommand(caption, commandFunc, accessKey) { }
91 }
92
93 // GM Resource not supported
94 if(typeof GM_getResourceText === "undefined") {
95 function GM_getResourceText(resourceName) {
96 throw ("eric6 Web Browser: GM Resource is not supported!");
97 }
98 }
99
100 if(typeof GM_getResourceURL === "undefined") {
101 function GM_getResourceURL(resourceName) {
102 throw ("eric6 Web Browser: GM Resource is not supported!");
103 }
104 }
105
106 // GM Settings not supported
107 if(typeof GM_getValue === "undefined") {
108 function GM_getValue(name, defaultValue) {
109 return defaultValue;
110 }
111 }
112
113 if(typeof GM_setValue === "undefined") {
114 function GM_setValue(name, value) { }
115 }
116
117 if(typeof GM_deleteValue === "undefined") {
118 function GM_deleteValue(name) { }
119 }
120
121 if(typeof GM_listValues === "undefined") {
122 function GM_listValues() {
123 return new Array("");
124 }
125 }
126 """

eric ide

mercurial