|
21 | 21 | // ==/UserScript== |
22 | 22 |
|
23 | 23 | (function () { |
24 | | - // user configuration |
25 | | - const config = { |
26 | | - urlOverride: "", |
27 | | - /* the script tries to automatically find earthlng's aboutconfig URL, and if it can't be |
28 | | - found, uses the built-in about:config URL instead. if it's unable to find the URL for your |
29 | | - particular setup, or if you just want to use the vanilla about:config page, replace this |
30 | | - empty string with your preferred URL, in quotes. if you want to use my about:cfg script that |
31 | | - registers earthlng's aboutconfig page to about:cfg, and you want the about:config button to |
32 | | - take you to about:cfg, then leave this empty. it will automatically use about:cfg if the |
33 | | - script exists. if about:cfg doesn't work for you then change the urlOverride in *that* |
34 | | - script instead of this one. */ |
35 | | - }; |
| 24 | + // user configuration |
| 25 | + const config = { |
| 26 | + urlOverride: "", |
| 27 | + /* the script tries to automatically find earthlng's aboutconfig URL, |
| 28 | + and if it can't be found, uses the built-in about:config URL instead. if |
| 29 | + it's unable to find the URL for your particular setup, or if you just |
| 30 | + want to use the vanilla about:config page, replace this empty string |
| 31 | + with your preferred URL, in quotes. if you want to use my about:cfg |
| 32 | + script that registers earthlng's aboutconfig page to about:cfg, and you |
| 33 | + want the about:config button to take you to about:cfg, then leave this |
| 34 | + empty. it will automatically use about:cfg if the script exists. if |
| 35 | + about:cfg doesn't work for you then change the pathOverride in *that* |
| 36 | + script instead of setting urlOverride in this one. if you changed the |
| 37 | + address (the "cfg" string) in that script, you'll need to use |
| 38 | + urlOverride here if you want the button to direct to earthlng's |
| 39 | + aboutconfig page. so if for example you changed the address to "config2" |
| 40 | + then change urlOverride above to "about:config2" */ |
| 41 | + }; |
36 | 42 |
|
37 | | - let { interfaces: Ci, manager: Cm } = Components; |
| 43 | + let { interfaces: Ci, manager: Cm } = Components; |
38 | 44 |
|
39 | | - function findAboutConfig() { |
40 | | - if (config.urlOverride) return config.urlOverride; |
| 45 | + function findAboutConfig() { |
| 46 | + if (config.urlOverride) return config.urlOverride; |
41 | 47 |
|
42 | | - if ( |
43 | | - Cm.QueryInterface(Ci.nsIComponentRegistrar).isContractIDRegistered( |
44 | | - "@mozilla.org/network/protocol/about;1?what=cfg" |
45 | | - ) |
46 | | - ) |
47 | | - return "about:cfg"; |
| 48 | + if ( |
| 49 | + Cm.QueryInterface(Ci.nsIComponentRegistrar).isContractIDRegistered( |
| 50 | + "@mozilla.org/network/protocol/about;1?what=cfg" |
| 51 | + ) |
| 52 | + ) |
| 53 | + return "about:cfg"; |
48 | 54 |
|
49 | | - let dir = Services.dirsvc.get("UChrm", Ci.nsIFile); |
50 | | - let appendFn = (nm) => dir.append(nm); |
| 55 | + let dir = Services.dirsvc.get("UChrm", Ci.nsIFile); |
| 56 | + let appendFn = nm => dir.append(nm); |
51 | 57 |
|
52 | | - // fx-autoconfig |
53 | | - ["resources", "aboutconfig", "config.xhtml"].forEach(appendFn); |
54 | | - if (dir.exists()) return "chrome://userchrome/content/aboutconfig/config.xhtml"; |
| 58 | + // fx-autoconfig |
| 59 | + ["resources", "aboutconfig", "config.xhtml"].forEach(appendFn); |
| 60 | + if (dir.exists()) return "chrome://userchrome/content/aboutconfig/config.xhtml"; |
55 | 61 |
|
56 | | - // earthlng's loader |
57 | | - dir = Services.dirsvc.get("UChrm", Ci.nsIFile); |
58 | | - ["utils", "aboutconfig", "config.xhtml"].forEach(appendFn); |
59 | | - if (dir.exists()) return "chrome://userchromejs/content/aboutconfig/config.xhtml"; |
| 62 | + // earthlng's loader |
| 63 | + dir = Services.dirsvc.get("UChrm", Ci.nsIFile); |
| 64 | + ["utils", "aboutconfig", "config.xhtml"].forEach(appendFn); |
| 65 | + if (dir.exists()) return "chrome://userchromejs/content/aboutconfig/config.xhtml"; |
60 | 66 |
|
61 | | - // xiaoxiaoflood's loader |
62 | | - dir = Services.dirsvc.get("UChrm", Ci.nsIFile); |
63 | | - ["utils", "aboutconfig", "aboutconfig.xhtml"].forEach(appendFn); |
64 | | - if (dir.exists()) return "chrome://userchromejs/content/aboutconfig/aboutconfig.xhtml"; |
| 67 | + // xiaoxiaoflood's loader |
| 68 | + dir = Services.dirsvc.get("UChrm", Ci.nsIFile); |
| 69 | + ["utils", "aboutconfig", "aboutconfig.xhtml"].forEach(appendFn); |
| 70 | + if (dir.exists()) return "chrome://userchromejs/content/aboutconfig/aboutconfig.xhtml"; |
65 | 71 |
|
66 | | - // no about:config replacement found |
67 | | - return "about:config"; |
68 | | - } |
| 72 | + // no about:config replacement found |
| 73 | + return "about:config"; |
| 74 | + } |
69 | 75 |
|
70 | | - async function createButton() { |
71 | | - // get fluent file for AboutConfig page |
72 | | - const configStrings = await new Localization(["toolkit/about/config.ftl"], true); |
73 | | - // localize the "Advanced Preferences" string |
74 | | - const advancedPrefsLabel = await configStrings.formatValue(["about-config-page-title"]); |
75 | | - const { mainView } = PanelUI; |
76 | | - const doc = mainView.ownerDocument; |
77 | | - const settingsButton = |
78 | | - doc.getElementById("appMenu-settings-button") ?? |
79 | | - doc.getElementById("appMenu-preferences-button"); |
80 | | - const prefsButton = doc.createXULElement("toolbarbutton"); |
| 76 | + async function createButton() { |
| 77 | + // get fluent file for AboutConfig page |
| 78 | + const configStrings = await new Localization(["toolkit/about/config.ftl"], true); |
| 79 | + // localize the "Advanced Preferences" string |
| 80 | + const advancedPrefsLabel = await configStrings.formatValue(["about-config-page-title"]); |
| 81 | + const { mainView } = PanelUI; |
| 82 | + const doc = mainView.ownerDocument; |
| 83 | + const settingsButton = |
| 84 | + doc.getElementById("appMenu-settings-button") ?? |
| 85 | + doc.getElementById("appMenu-preferences-button"); |
| 86 | + const prefsButton = doc.createXULElement("toolbarbutton"); |
81 | 87 |
|
82 | | - prefsButton.preferredURL = findAboutConfig(); |
83 | | - for (const [key, val] of Object.entries({ |
84 | | - id: "appMenu-advanced-settings-button", |
85 | | - class: "subviewbutton", |
86 | | - label: advancedPrefsLabel, |
87 | | - oncommand: `openTrustedLinkIn(this.preferredURL, gBrowser.currentURI.spec === AboutNewTab.newTabURL || gBrowser.currentURI.spec === HomePage.get(window) ? "current" : "tab")`, |
88 | | - })) |
89 | | - prefsButton.setAttribute(key, val); |
90 | | - // place after the built-in "Settings" button |
91 | | - settingsButton.after(prefsButton); |
92 | | - } |
| 88 | + prefsButton.preferredURL = findAboutConfig(); |
| 89 | + for (const [key, val] of Object.entries({ |
| 90 | + id: "appMenu-advanced-settings-button", |
| 91 | + class: "subviewbutton", |
| 92 | + label: advancedPrefsLabel, |
| 93 | + oncommand: `openTrustedLinkIn(this.preferredURL, gBrowser.currentURI.spec === AboutNewTab.newTabURL || gBrowser.currentURI.spec === HomePage.get(window) ? "current" : "tab")`, |
| 94 | + })) |
| 95 | + prefsButton.setAttribute(key, val); |
| 96 | + // place after the built-in "Settings" button |
| 97 | + settingsButton.after(prefsButton); |
| 98 | + } |
93 | 99 |
|
94 | | - function init() { |
95 | | - PanelMultiView.getViewNode(document, "appMenu-multiView").addEventListener( |
96 | | - "ViewShowing", |
97 | | - createButton, |
98 | | - { once: true } |
99 | | - ); |
100 | | - } |
| 100 | + function init() { |
| 101 | + PanelMultiView.getViewNode(document, "appMenu-multiView").addEventListener( |
| 102 | + "ViewShowing", |
| 103 | + createButton, |
| 104 | + { once: true } |
| 105 | + ); |
| 106 | + } |
101 | 107 |
|
102 | | - if (gBrowserInit.delayedStartupFinished) { |
| 108 | + if (gBrowserInit.delayedStartupFinished) { |
| 109 | + init(); |
| 110 | + } else { |
| 111 | + let delayedListener = (subject, topic) => { |
| 112 | + if (topic == "browser-delayed-startup-finished" && subject == window) { |
| 113 | + Services.obs.removeObserver(delayedListener, topic); |
103 | 114 | init(); |
104 | | - } else { |
105 | | - let delayedListener = (subject, topic) => { |
106 | | - if (topic == "browser-delayed-startup-finished" && subject == window) { |
107 | | - Services.obs.removeObserver(delayedListener, topic); |
108 | | - init(); |
109 | | - } |
110 | | - }; |
111 | | - Services.obs.addObserver(delayedListener, "browser-delayed-startup-finished"); |
112 | | - } |
| 115 | + } |
| 116 | + }; |
| 117 | + Services.obs.addObserver(delayedListener, "browser-delayed-startup-finished"); |
| 118 | + } |
113 | 119 | })(); |
0 commit comments