Skip to content

Commit

Permalink
(JS) update some scripts to take advantage of the
Browse files Browse the repository at this point in the history
PanelMultiView enhancement in bug 1724622.
  • Loading branch information
aminomancer committed Jun 4, 2022
1 parent a939a7e commit d4f9899
Show file tree
Hide file tree
Showing 4 changed files with 969 additions and 1,010 deletions.
138 changes: 69 additions & 69 deletions JS/appMenuMods.uc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name App Menu Mods
// @version 1.4.0
// @version 1.4.1
// @author aminomancer
// @homepage https://github.com/aminomancer/uc.css.js
// @description Makes some minor modifications to the app menu (the popup
Expand All @@ -12,74 +12,74 @@
// ==/UserScript==

(function () {
class AppMenuMods {
constructor() {
PanelUI._initialized || PanelUI.init(shouldSuppressPopupNotifications);
PanelUI.mainView.addEventListener("ViewShowing", this, { once: true });
this.addSeparatorToAccountPanel();
this.fixSyncSubviewButtonAlignment();
}
static create(aDoc, tag, props, isHTML = false) {
let el = isHTML ? aDoc.createElement(tag) : aDoc.createXULElement(tag);
for (let prop in props) {
el.setAttribute(prop, props[prop]);
}
return el;
}
static sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async generateStrings() {
if (!this.strings)
this.strings = await new Localization(["toolkit/about/aboutSupport.ftl"], true);
await AppMenuMods.sleep(1);
return this.strings;
}
get fxaPanelView() {
return PanelMultiView.getViewNode(document, "PanelUI-fxa");
}
async handleEvent(_e) {
let strings = await this.generateStrings();
this.addRestartButton(strings);
}
addSeparatorToAccountPanel() {
this.manageAccountSeparator =
this.fxaPanelView.ownerDocument.createXULElement("toolbarseparator");
this.fxaPanelView
.querySelector("#fxa-manage-account-button")
.after(this.manageAccountSeparator);
}
async addRestartButton(strings) {
let restartButton = AppMenuMods.create(document, "toolbarbutton", {
id: "appMenu-restart-button2",
class: "subviewbutton",
label: await strings.formatValue(["restart-button-label"]),
oncommand: `if (event.shiftKey || (AppConstants.platform == "macosx" ? event.metaKey : event.ctrlKey)) Services.appinfo.invalidateCachesOnRestart(); setTimeout(() => Services.startup.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit), 300); this.closest("panel").hidePopup(true); event.preventDefault();`,
onclick: `if (event.button === 0) return; Services.appinfo.invalidateCachesOnRestart(); setTimeout(() => Services.startup.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit), 300); this.closest("panel").hidePopup(true); event.preventDefault();`,
});
let exitButton = document.getElementById("appMenu-quit-button2");
if (exitButton) exitButton.before(restartButton);
else PanelUI.mainView.querySelector(".panel-subview-body").appendChild(restartButton);
}
fixSyncSubviewButtonAlignment() {
eval(
`gSync.populateSendTabToDevicesView = function ` +
gSync.populateSendTabToDevicesView
.toSource()
.replace(/^populateSendTabToDevicesView/, ``)
.replace(/item.setAttribute\(\"align\", \"start\"\);/, ``)
);
}
class AppMenuMods {
constructor() {
PanelUI._initialized || PanelUI.init(shouldSuppressPopupNotifications);
PanelUI.mainView.addEventListener("ViewShowing", this, { once: true });
this.addSeparatorToAccountPanel();
this.fixSyncSubviewButtonAlignment();
}

if (gBrowserInit.delayedStartupFinished) new AppMenuMods();
else {
let delayedListener = (subject, topic) => {
if (topic == "browser-delayed-startup-finished" && subject == window) {
Services.obs.removeObserver(delayedListener, topic);
new AppMenuMods();
}
};
Services.obs.addObserver(delayedListener, "browser-delayed-startup-finished");
static create(aDoc, tag, props, isHTML = false) {
let el = isHTML ? aDoc.createElement(tag) : aDoc.createXULElement(tag);
for (let prop in props) {
el.setAttribute(prop, props[prop]);
}
return el;
}
static sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async generateStrings() {
if (!this.strings)
this.strings = await new Localization(["toolkit/about/aboutSupport.ftl"], true);
await AppMenuMods.sleep(1);
return this.strings;
}
get fxaPanelView() {
return PanelMultiView.getViewNode(document, "PanelUI-fxa");
}
async handleEvent(_e) {
let strings = await this.generateStrings();
this.addRestartButton(strings);
}
addSeparatorToAccountPanel() {
this.manageAccountSeparator =
this.fxaPanelView.ownerDocument.createXULElement("toolbarseparator");
this.fxaPanelView
.querySelector("#fxa-manage-account-button")
.after(this.manageAccountSeparator);
}
async addRestartButton(strings) {
let restartButton = AppMenuMods.create(document, "toolbarbutton", {
id: "appMenu-restart-button2",
class: "subviewbutton",
label: await strings.formatValue(["restart-button-label"]),
oncommand: `if (event.shiftKey || (AppConstants.platform == "macosx" ? event.metaKey : event.ctrlKey)) Services.appinfo.invalidateCachesOnRestart(); setTimeout(() => Services.startup.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit), 300); PanelMultiView.forNode(this.closest("panelmultiview")).hidePopup(); event.preventDefault();`,
onclick: `if (event.button === 0) return; Services.appinfo.invalidateCachesOnRestart(); setTimeout(() => Services.startup.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit), 300); PanelMultiView.forNode(this.closest("panelmultiview")).hidePopup(); event.preventDefault();`,
});
let exitButton = document.getElementById("appMenu-quit-button2");
if (exitButton) exitButton.before(restartButton);
else PanelUI.mainView.querySelector(".panel-subview-body").appendChild(restartButton);
}
fixSyncSubviewButtonAlignment() {
eval(
`gSync.populateSendTabToDevicesView = function ` +
gSync.populateSendTabToDevicesView
.toSource()
.replace(/^populateSendTabToDevicesView/, ``)
.replace(/item.setAttribute\(\"align\", \"start\"\);/, ``)
);
}
}

if (gBrowserInit.delayedStartupFinished) new AppMenuMods();
else {
let delayedListener = (subject, topic) => {
if (topic == "browser-delayed-startup-finished" && subject == window) {
Services.obs.removeObserver(delayedListener, topic);
new AppMenuMods();
}
};
Services.obs.addObserver(delayedListener, "browser-delayed-startup-finished");
}
})();
56 changes: 28 additions & 28 deletions JS/backspacePanelNav.uc.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
// ==UserScript==
// @name Backspace Panel Navigation
// @version 1.1.0
// @version 1.1.1
// @author aminomancer
// @homepage https://github.com/aminomancer
// @description Press backspace to navigate back/forward in popup panels.
// @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 () {
function init() {
const pc = Object.getPrototypeOf(PanelView.forNode(PanelUI.mainView));
eval(
`pc.keyNavigation = function ` +
pc.keyNavigation
.toSource()
.replace(/^\(/, "")
.replace(/\)$/, "")
.replace(/^keyNavigation\s*/, "")
.replace(/^function\s*/, "")
.replace(
/(case \"ArrowLeft\"\:)/,
`case "Backspace":
function init() {
const pc = Object.getPrototypeOf(PanelView.forNode(PanelUI.mainView));
eval(
`pc.keyNavigation = function ` +
pc.keyNavigation
.toSource()
.replace(/^\(/, "")
.replace(/\)$/, "")
.replace(/^keyNavigation\s*/, "")
.replace(/^function\s*/, "")
.replace(
/(case \"ArrowLeft\"\:)/,
`case "Backspace":
if (tabOnly() || isContextMenuOpen()) {
break;
}
stop();
if (PanelMultiView.forNode(this.node.panelMultiView).openViews.length > 1) {
this.node.panelMultiView.goBack();
} else {
PanelMultiView.forNode(this.node.panelMultiView)._panel.hidePopup(true);
PanelMultiView.forNode(this.node.panelMultiView).hidePopup(true);
}
break;
$1`
)
);
}
)
);
}

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");
}
})();
20 changes: 1 addition & 19 deletions JS/miscMods.uc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name Misc. Mods
// @version 1.9.3
// @version 1.9.4
// @author aminomancer
// @homepage https://github.com/aminomancer/uc.css.js
// @description Various tiny mods not worth making separate scripts for. Read the comments inside the script for details.
Expand Down Expand Up @@ -61,11 +61,6 @@
// :is(#reload-button, #stop-button) > .toolbarbutton-icon {padding: var(--toolbarbutton-inner-padding) !important;}
"Allow stop/reload button to animate in other toolbars": true,

// the toast popup that opens when you enable/disable tracking protection on a site has a
// bug where it doesn't fade out when it closes. see here:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1724622
"Fix missing tracking protection toast popup fade animation": true,

// When you open a private window, it shows a little private browsing icon in the top of the
// navbar, next to the window control buttons. It doesn't have a tooltip for some reason, so
// if you don't already recognize the private browsing icon, you won't know what it means.
Expand Down Expand Up @@ -132,8 +127,6 @@
this.reduceCtrlTabDelay(config["Reduce ctrl+tab delay"]);
if (config["Allow stop/reload button to animate in other toolbars"])
this.stopReloadAnimations();
if (config["Fix missing tracking protection toast popup fade animation"])
this.fixProtectionsToast();
if (config["Give the private browsing indicator a tooltip"])
this.addPrivateBrowsingTooltip();
if (config["Preserve your default bookmarks folder"])
Expand Down Expand Up @@ -258,17 +251,6 @@
.replace(/#nav-bar-customization-target/, `.customization-target`)
);
}
fixProtectionsToast() {
eval(
`gProtectionsHandler.showProtectionsPopup = function ` +
gProtectionsHandler.showProtectionsPopup
.toSource()
.replace(
/PanelMultiView\.hidePopup\(this\.\_protectionsPopup\)/,
`this._protectionsPopup.hidePopup(true)`
)
);
}
async addPrivateBrowsingTooltip() {
this.privateL10n = await new Localization(["browser/aboutPrivateBrowsing.ftl"], true);
let l10nId = PrivateBrowsingUtils.isWindowPrivate(window)
Expand Down

0 comments on commit d4f9899

Please sign in to comment.