-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmenu.js
More file actions
79 lines (73 loc) · 2.27 KB
/
menu.js
File metadata and controls
79 lines (73 loc) · 2.27 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
var str_switch;
var type_switch;
if (isFirefox) {
str_switch = "Disable";
type_switch = "checkbox";
} else if (isChrome) {
str_switch = "Switch enable/disable"
type_switch = "normal";
}
browser.contextMenus.create({
contexts: ["browser_action"],
id: "checkbox_t_disable",
type: type_switch,
title: `${str_switch} ${addon_name} on this tab`
});
browser.contextMenus.create({
contexts: ["browser_action"],
id: "checkbox_h_disable",
type: type_switch,
title: `${str_switch} ${addon_name} on this tab and new tabs opened by this tab`
});
browser.contextMenus.create({
contexts: ["browser_action"],
type: "separator",
});
if (isFirefox) {
browser.contextMenus.create({
contexts: ["browser_action"],
id: "checkbox_w_disable",
type: type_switch,
title: `${str_switch} ${addon_name} in this window`
});
}
browser.contextMenus.create({
contexts: ["browser_action"],
id: "checkbox_global_disable",
type: type_switch,
title: `${str_switch} ${addon_name} globally`
});
if (isFirefox) {
browser.contextMenus.onShown.addListener(updateMenuCheckboxes);
} else if (isChrome) {
}
async function updateMenuCheckboxes(info, tab) {
const tabid = tab.id;
const wid = tab.windowId;
browser.contextMenus.update("checkbox_global_disable", {checked: ! isGlobalEnabled() });
browser.contextMenus.update("checkbox_w_disable", {checked: isWindowDisabled(wid) });
browser.contextMenus.update("checkbox_t_disable", {checked: isTabIn_list_t(tabid) });
browser.contextMenus.update("checkbox_h_disable", {checked: isTabIn_list_h(tabid) });
// Note: Not waiting for returned promise.
browser.contextMenus.refresh();
}
browser.contextMenus.onClicked.addListener((info, tab) => {
const tabid = tab.id;
const wid = tab.windowId;
const checked = info.checked;
const menuItemId = info.menuItemId;
switch ( menuItemId ){
case "checkbox_global_disable":
toggle_global_enabled();
break;
case "checkbox_w_disable":
toggle_window_disabled(wid);
break;
case "checkbox_t_disable":
toggleTab_t(tabid);
break;
case "checkbox_h_disable":
toggleTab_h(tabid);
break;
}
});