forked from aminomancer/uc.css.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appMenuMods.uc.js
123 lines (121 loc) · 4.66 KB
/
appMenuMods.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
114
115
116
117
118
119
120
121
122
123
// ==UserScript==
// @name App Menu Mods
// @version 1.4.4
// @author aminomancer
// @homepageURL https://github.com/aminomancer/uc.css.js
// @description Makes some minor modifications to the app menu (the popup opened by clicking the hamburger button on the far right of the navbar). It adds a restart button to the app menu and it adds a separator under the "Manage Account" button in the profile/account panel. I'll continue adding more mods to this script as I think of them.
// @downloadURL https://cdn.jsdelivr.net/gh/aminomancer/uc.css.js@master/JS/appMenuMods.uc.js
// @updateURL https://cdn.jsdelivr.net/gh/aminomancer/uc.css.js@master/JS/appMenuMods.uc.js
// @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() {
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: /* javascript */ `
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: /* javascript */ `
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"
);
}
})();