forked from benzBrake/FirefoxCustomize
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenubarReplaceWithButton.uc.js
More file actions
95 lines (90 loc) · 3.97 KB
/
MenubarReplaceWithButton.uc.js
File metadata and controls
95 lines (90 loc) · 3.97 KB
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
// ==UserScript==
// @name MenubarReplaceWithButton.uc.js
// @description 把主菜单替换成按钮
// @author unknown
// @include main
// ==/UserScript==
(function () {
if (location != 'chrome://browser/content/browser.xhtml') return;
try {
CustomizableUI.createWidget({
id: 'main-menubar_button',
type: 'custom',
defaultArea: CustomizableUI.AREA_NAVBAR,
onBuild: function (aDocument) {
let toolbaritem = aDocument.createXULElement('toolbarbutton');
let props = {
id: 'main-menubar_button',
class: 'toolbarbutton-1 chromeclass-toolbar-additional',
removable: false,
label: Services.locale.appLocaleAsBCP47.includes("zh") ? "主菜单" : "メニューバー",
tooltiptext: Services.locale.appLocaleAsBCP47.includes("zh") ? "主菜单" : "メニューバー",
style: 'list-style-image: url("chrome://global/skin/icons/more.svg");',
popup: 'main-menubar_popup',
};
for (let p in props) toolbaritem.setAttribute(p, props[p]);
return toolbaritem;
}
});
} catch (e) { };
})();
window.addEventListener("MozAfterPaint", function () {
// ポップアップメニューが無かったら作成
if (!document.getElementById('main-menubar_popup')) {
// ポップアップ作成
let menupopup = document.createXULElement('menupopup');
menupopup.setAttribute('id', 'main-menubar_popup');
// menubarにあったから付けてみた
menupopup.setAttribute('onpopupshowing',
`if (event.target.parentNode.parentNode == this &&
!('@mozilla.org/widget/nativemenuservice;1' in Cc))
this.setAttribute('openedwithkey',
event.target.parentNode.openedWithKey);
// 開かれたらopen追加
if (event.target != this) return true;
document.getElementById('main-menubar_button').setAttribute('open', 'true');`);
menupopup.setAttribute('onpopuphiding',
// 閉じたらopen削除
`if (event.target != this) return;
document.getElementById('main-menubar_button').removeAttribute('open');`);
// メニューの位置
menupopup.setAttribute('position', 'after_start');
document.getElementById('mainPopupSet').append(menupopup);
// メニューをメニューバーからポップアップに移動
let menubar = document.getElementById('main-menubar');
let cl = menubar.childNodes.length;
for (let i = 0; i < cl; ++i) {
// 子要素がmenuと決め打ち
let menu = menubar.firstChild;
if (menu.nodeName === 'menu') {
menu.setAttribute('class', 'menu-iconic');
let menutxt = menu.firstChild;
if (menutxt.classList.contains('menubar-text')) {
// labelのclass替えとvalueとkey取得
menutxt.classList.remove('menubar-text');
menutxt.classList.add('menu-iconic-text');
menutxt.setAttribute('flex', '1');
// menu-left作成
let menuleft = MozXULElement.parseXULToFragment(`
<hbox class="menu-iconic-left" align="center" pack="center" aria-hidden="true">
<image/>
</hbox>
`);
menu.prepend(menuleft);
// menu-right作成
let menuright = MozXULElement.parseXULToFragment(`
<hbox class="menu-accel-container" anonid="accel" aria-hidden="true">
<label class="menu-iconic-accel"/>
</hbox>
<hbox align="center" class="menu-right" aria-hidden="true">
<image/>
</hbox>
`);
menutxt.after(menuright);
}
menupopup.append(menu);
}
}
// document.getElementById('menubar-items').removeChild(menubar);
}
}, { once: true });