aboutsummaryrefslogtreecommitdiffhomepage
path: root/addon/background.js
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-10-30 23:03:13 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-10-31 11:31:00 +0800
commit3e78ee2ffbb9f10f4d8fa30723f02a752fa402e1 (patch)
treee0c516aea43f2577a524688974b2da5cc34cc01a /addon/background.js
parent2a01edfbe920db25ca752371b889b08dce9025ac (diff)
feat: add context menu-item to disable custom menu
Diffstat (limited to 'addon/background.js')
-rw-r--r--addon/background.js23
1 files changed, 20 insertions, 3 deletions
diff --git a/addon/background.js b/addon/background.js
index ac742ab..c723b4c 100644
--- a/addon/background.js
+++ b/addon/background.js
@@ -4,7 +4,23 @@ browser.contextMenus.create(
4 { 4 {
5 id: 'map-inline-add', 5 id: 'map-inline-add',
6 title: 'Add Links and Maps by content', 6 title: 'Add Links and Maps by content',
7 contexts: ['page'], 7 contexts: ['all'],
8 },
9)
10
11browser.contextMenus.create(
12 {
13 id: 'map-inline-menu',
14 title: 'Enable Menu',
15 type: 'checkbox',
16 checked: true,
17 contexts: ['all'],
18 },
19)
20
21browser.contextMenus.create(
22 {
23 type: 'separator',
8 }, 24 },
9) 25)
10 26
@@ -12,16 +28,17 @@ browser.contextMenus.create(
12 { 28 {
13 id: 'map-inline-open', 29 id: 'map-inline-open',
14 title: 'Open in DumbyMap', 30 title: 'Open in DumbyMap',
15 contexts: ['page', 'selection'], 31 contexts: ['all'],
16 }, 32 },
17 () => browser.runtime.lastError, 33 () => browser.runtime.lastError,
18) 34)
19 35
20browser.contextMenus.onClicked.addListener((info, tab) => { 36browser.contextMenus.onClicked.addListener((info, tab) => {
21 const id = info.menuItemId 37 const id = info.menuItemId
38 const checked = info.checked
22 if (!id.match(/^map-inline/)) return 39 if (!id.match(/^map-inline/)) return
23 40
24 browser.tabs.sendMessage(tab.id, id) 41 browser.tabs.sendMessage(tab.id, { id, checked })
25}) 42})
26 43
27browser.browserAction.onClicked.addListener((info) => { 44browser.browserAction.onClicked.addListener((info) => {