forked from aminomancer/uc.css.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appMenuAboutConfigButton.uc.js
113 lines (100 loc) · 5.8 KB
/
appMenuAboutConfigButton.uc.js
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// ==UserScript==
// @name App Menu about:config Button
// @version 1.2.2
// @author aminomancer
// @homepage https://github.com/aminomancer/uc.css.js
// @description Adds an about:config shortcut button to the main app menu panel, under the
// built-in Settings button. It can open the built-in about:config page, or it can open the
// old-school about:config page with earthlng's aboutconfig module. (https://github.com/earthlng/aboutconfig)
// To use that with fx-autoconfig, download ONLY the profile/chrome/utils/aboutconfig folder and
// place it inside your profile/chrome/resources folder. Then open config.xhtml and find & replace
// "userchromejs" with "userchrome" and save. Now "chrome://userchrome/content/aboutconfig/config.xhtml"
// should be the correct URL. By default the script will open to that link, so if you don't have
// that module installed the button will open to a blank page. If you can't get the module to work
// or if you just prefer Firefox's built-in page, you can change the constant on line 10 below to
// "about:config" and it'll open to the same page you'd get if you typed about:config in the address
// bar. (the URL must be in quotes) That said, typing about:config is already easy enough. The
// reason I made this script was to make a clean shortcut to reach the old-school page, and in a
// more central location than a bookmark. FYI I added an icon for this button (and for all the other
// main app menu buttons too) in uc-app-menu.css
// @license This Source Code Form is subject to the terms of the Creative Commons Attribution-NonCommercial-ShareAlike International License, v. 4.0. If a copy of the CC BY-NC-SA 4.0 was not distributed with this file, You can obtain one at http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
// ==/UserScript==
(function () {
// user configuration
const config = {
urlOverride: "",
/* the script tries to automatically find earthlng's aboutconfig URL, and if it can't be
found, uses the built-in about:config URL instead. if it's unable to find the URL for your
particular setup, or if you just want to use the vanilla about:config page, replace this
empty string with your preferred URL, in quotes. if you want to use my about:cfg script that
registers earthlng's aboutconfig page to about:cfg, and you want the about:config button to
take you to about:cfg, then leave this empty. it will automatically use about:cfg if the
script exists. if about:cfg doesn't work for you then change the urlOverride in *that*
script instead of this one. */
};
let { interfaces: Ci, manager: Cm } = Components;
function findAboutConfig() {
if (config.urlOverride) return config.urlOverride;
if (
Cm.QueryInterface(Ci.nsIComponentRegistrar).isContractIDRegistered(
"@mozilla.org/network/protocol/about;1?what=cfg"
)
)
return "about:cfg";
let dir = Services.dirsvc.get("UChrm", Ci.nsIFile);
let appendFn = (nm) => dir.append(nm);
// fx-autoconfig
["resources", "aboutconfig", "config.xhtml"].forEach(appendFn);
if (dir.exists()) return "chrome://userchrome/content/aboutconfig/config.xhtml";
// earthlng's loader
dir = Services.dirsvc.get("UChrm", Ci.nsIFile);
["utils", "aboutconfig", "config.xhtml"].forEach(appendFn);
if (dir.exists()) return "chrome://userchromejs/content/aboutconfig/config.xhtml";
// xiaoxiaoflood's loader
dir = Services.dirsvc.get("UChrm", Ci.nsIFile);
["utils", "aboutconfig", "aboutconfig.xhtml"].forEach(appendFn);
if (dir.exists()) return "chrome://userchromejs/content/aboutconfig/aboutconfig.xhtml";
// no about:config replacement found
return "about:config";
}
async function createButton() {
// get fluent file for AboutConfig page
const configStrings = await new Localization(["toolkit/about/config.ftl"], true);
// localize the "Advanced Preferences" string
const advancedPrefsLabel = await configStrings.formatValue(["about-config-page-title"]);
const { mainView } = PanelUI;
const doc = mainView.ownerDocument;
const settingsButton =
doc.getElementById("appMenu-settings-button") ??
doc.getElementById("appMenu-preferences-button");
const prefsButton = doc.createXULElement("toolbarbutton");
prefsButton.preferredURL = findAboutConfig();
for (const [key, val] of Object.entries({
id: "appMenu-advanced-settings-button",
class: "subviewbutton",
label: advancedPrefsLabel,
oncommand: `openTrustedLinkIn(this.preferredURL, gBrowser.currentURI.spec === AboutNewTab.newTabURL || gBrowser.currentURI.spec === HomePage.get(window) ? "current" : "tab")`,
}))
prefsButton.setAttribute(key, val);
// place after the built-in "Settings" button
settingsButton.after(prefsButton);
}
function init() {
PanelMultiView.getViewNode(document, "appMenu-multiView").addEventListener(
"ViewShowing",
createButton,
{ once: true }
);
}
if (gBrowserInit.delayedStartupFinished) {
init();
} else {
let delayedListener = (subject, topic) => {
if (topic == "browser-delayed-startup-finished" && subject == window) {
Services.obs.removeObserver(delayedListener, topic);
init();
}
};
Services.obs.addObserver(delayedListener, "browser-delayed-startup-finished");
}
})();