forked from ywzhaiqi/userChromeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JSOff.uc.xul
89 lines (69 loc) · 5.19 KB
/
JSOff.uc.xul
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE overlay>
<overlay id="jsoff-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript"><![CDATA[
if ("undefined" == typeof(jsoffNamespace)) {
var jsoffNamespace = {};
};
jsoffNamespace.ON_IMG = "data:image/gif;base64,R0lGODlhEAAQAPYAAAAAAAiAAAmGAAmOAAqWAAueAAuiAAumAAuoAAukAAmEAABSAQBcAgmMAAmIAABYAof%2FOQqSAABeAgEBARNAABVCAAqYAAqaAAyyAAy6ABKgAAyuAAqcAAy0ABG%2BABfGAAywAA28ABbEAAMuAAMmAAMqAAMsAAy2AAysAAAEAFL%2BAFv%2FFYH%2FNwdyAAMMAHr%2FMwugAAACAEjwABZKAAMKACh8AD7OAAEQAABUAQh4AAAWAAUOAD7QAIb%2FN3T%2FMTWwAAIFAQRCAABIAQduAAA2AQAcAAEUAAVIAAmKAABKAQBGAQBCAQdmAAp0AAh6AAmCAAh0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAFEALAAAAAAQABAAAAifAAEIHEiwoEAHCC1YQMAQwUILCAXmwIHDIEE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AAOw%3D%3D";
jsoffNamespace.jsStatus = function () {
var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
return {
startup : function(){
this.setStatusBar();
},
// run this onClick from the status bar
run : function () {
var jsEnabled = prefManager.getBoolPref("javascript.enabled");
prefManager.setBoolPref("javascript.enabled", !jsEnabled);
// change propogation handled in observer, don't need to call setStatusBar here
},
// something changed, update UI
setStatusBar : function(){
var statusBar = document.getElementById('jsoff-statusbar');
var jsEnabled = prefManager.getBoolPref("javascript.enabled");
statusBar.src = jsEnabled ? jsoffNamespace.ON_IMG : jsoffNamespace.OFF_IMG;
}
};
}();
/*** jsStatus ***/
// This handles watching preferences for changes to javascript options
jsoffNamespace.myPrefObserver =
{
register: function()
{
// First we'll need the preference services to look for preferences.
var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
// For this._branch we ask that the preferences for extensions.myextension. and children
this._branch = prefService.getBranch("javascript.");
// Now we queue the interface called nsIPrefBranch2. This interface is described as:
// "nsIPrefBranch2 allows clients to observe changes to pref values."
this._branch.QueryInterface(Components.interfaces.nsIPrefBranch2);
// Finally add the observer.
this._branch.addObserver("", this, false);
},
unregister: function()
{
if(!this._branch) return;
this._branch.removeObserver("", this);
},
observe: function(aSubject, aTopic, aData)
{
if(aTopic != "nsPref:changed") return;
// aSubject is the nsIPrefBranch we're observing (after appropriate QI)
// aData is the name of the pref that's been changed (relative to aSubject)
switch (aData) {
case "enabled":
jsoffNamespace.jsStatus.setStatusBar();
break;
}
}
}
jsoffNamespace.myPrefObserver.register();
window.addEventListener("load", function(e) { jsoffNamespace.jsStatus.startup(); }, false);
]]></script>
<statusbar id="status-bar">
<statusbarpanel id="jsoff-statusbar" class="statusbarpanel-menu-iconic" tooltiptext="Javascript 启用/禁用" src="data:image/gif;base64,R0lGODlhEAAQAPYAAAAAAAiAAAmGAAmOAAqWAAueAAuiAAumAAuoAAukAAmEAABSAQBcAgmMAAmIAABYAof%2FOQqSAABeAgEBARNAABVCAAqYAAqaAAyyAAy6ABKgAAyuAAqcAAy0ABG%2BABfGAAywAA28ABbEAAMuAAMmAAMqAAMsAAy2AAysAAAEAFL%2BAFv%2FFYH%2FNwdyAAMMAHr%2FMwugAAACAEjwABZKAAMKACh8AD7OAAEQAABUAQh4AAAWAAUOAD7QAIb%2FN3T%2FMTWwAAIFAQRCAABIAQduAAA2AQAcAAEUAAVIAAmKAABKAQBGAQBCAQdmAAp0AAh6AAmCAAh0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAFEALAAAAAAQABAAAAifAAEIHEiwoEAHCC1YQMAQwUILCAXmwIHDIEEHB3EgANCjo8eOACwItKBxIIWOFAaKBOBgIYIMKDj2CMlwpcKXHj7IBOAhg8ODLjPoBOnzZ0gSSEl42Fl0JUYVKwBk2FnT6c4cHF8AqIkRAFYVPVLW6GHjhkIcXXPcAGDjRY8XPwAogagEq1ciJAjeUOJAiV%2B7TJjkGIywsIPBTCwqFhgQADs%3D" onclick="jsoffNamespace.jsStatus.run()" />
</statusbar>
</overlay>