-
Notifications
You must be signed in to change notification settings - Fork 27
/
toggleMenubarHotkey.uc.js
75 lines (71 loc) · 3.03 KB
/
toggleMenubarHotkey.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
// ==UserScript==
// @name Toggle Menubar Hotkey
// @version 1.1.5
// @author aminomancer
// @homepageURL https://github.com/aminomancer
// @description Adds a hotkey (Alt+M by default) that toggles the menubar on and off. Unlike just pressing the Alt key, this keeps it open permanently until closed again by the hotkey, toolbar context menu, or customize menu. Requires [fx-autoconfig](https://github.com/MrOtherGuy/fx-autoconfig) — other script loaders will not work with this script.
// @downloadURL https://cdn.jsdelivr.net/gh/aminomancer/uc.css.js@master/JS/toggleMenubarHotkey.uc.js
// @updateURL https://cdn.jsdelivr.net/gh/aminomancer/uc.css.js@master/JS/toggleMenubarHotkey.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 () {
const options = {
// one or more of: alt, shift, ctrl, meta, accel. separated by space, enclosed by quotes.
modifiers: "alt",
// one of: A-Z, - (hyphen), or F1-F12. enclosed by quotes.
key: "M",
// key ID. don't change this.
id: "key_toggleMenubar",
};
let hotkeyRegistered = _ucUtils.registerHotkey(options, (win, key) => {
if (win === window) {
Services.obs.notifyObservers(
null,
"browser-set-toolbar-visibility",
JSON.stringify([
CustomizableUI.AREA_MENUBAR,
AutoHideMenubar._node.getAttribute("inactive"),
])
);
}
});
function init() {
if (!hotkeyRegistered) return;
document.getElementById("toolbar-menubar").setAttribute("key", options.id);
if (
ToolbarContextMenu.onViewToolbarsPopupShowing.name ===
"onViewToolbarsPopupShowing"
) {
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
CustomizableUI: "resource:///modules/CustomizableUI.sys.mjs",
SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
});
eval(
`ToolbarContextMenu.onViewToolbarsPopupShowing = function uc_onViewToolbarsPopupShowing ${ToolbarContextMenu.onViewToolbarsPopupShowing
.toSource()
.replace(/^\(/, "")
.replace(/\)$/, "")
.replace(/^onViewToolbarsPopupShowing/, "")
.replace(
/if \(popup\.id != \"toolbar-context-menu\"\)/,
`if (toolbar.hasAttribute("key"))`
)}`
);
}
}
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"
);
}
})();