Helpviewer/GreaseMonkey/GreaseMonkeyJavaScript.py

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

eric ide

mercurial