Skip to content

Commit

Permalink
(JS) fix restorePreProtonArrowpanels.
Browse files Browse the repository at this point in the history
it was previously not setting the open attribute on urlbar buttons.
refactor a few other scripts.
(CSS) minor improvements to bookmarks toolbar animations.
  • Loading branch information
aminomancer committed May 26, 2022
1 parent 7b961ce commit d3d367d
Show file tree
Hide file tree
Showing 8 changed files with 3,062 additions and 2,914 deletions.
158 changes: 82 additions & 76 deletions JS/appMenuAboutConfigButton.uc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,93 +21,99 @@
// ==/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. */
};
// 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 pathOverride in *that*
script instead of setting urlOverride in this one. if you changed the
address (the "cfg" string) in that script, you'll need to use
urlOverride here if you want the button to direct to earthlng's
aboutconfig page. so if for example you changed the address to "config2"
then change urlOverride above to "about:config2" */
};

let { interfaces: Ci, manager: Cm } = Components;
let { interfaces: Ci, manager: Cm } = Components;

function findAboutConfig() {
if (config.urlOverride) return config.urlOverride;
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";
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);
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";
// 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";
// 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";
// 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";
}
// 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");
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);
}
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 }
);
}
function init() {
PanelMultiView.getViewNode(document, "appMenu-multiView").addEventListener(
"ViewShowing",
createButton,
{ once: true }
);
}

if (gBrowserInit.delayedStartupFinished) {
if (gBrowserInit.delayedStartupFinished) {
init();
} else {
let delayedListener = (subject, topic) => {
if (topic == "browser-delayed-startup-finished" && subject == window) {
Services.obs.removeObserver(delayedListener, topic);
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");
}
}
};
Services.obs.addObserver(delayedListener, "browser-delayed-startup-finished");
}
})();

0 comments on commit d3d367d

Please sign in to comment.