From 62e7f371168917d005af1b3e6935716c1ff3d4a7 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sun, 20 Oct 2024 20:42:20 +0800 Subject: feat: add menu items --- addon/background.js | 18 ++++++++++++++---- addon/index.mjs | 4 +++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/addon/background.js b/addon/background.js index 24771aa..42e0c8d 100644 --- a/addon/background.js +++ b/addon/background.js @@ -2,15 +2,25 @@ console.log('background') browser.contextMenus.create( { - id: 'map-inline', - title: 'MapInline', + id: 'map-inline-add', + title: 'Add Links and Maps by content', + contexts: ['page'], + }, + () => void browser.runtime.lastError, +) + +browser.contextMenus.create( + { + id: 'map-inline-open', + title: 'Open in DumbyMap', contexts: ['page', 'selection'], }, () => void browser.runtime.lastError, ) browser.contextMenus.onClicked.addListener((info, tab) => { - if (info.menuItemId !== 'map-inline') return + const id = info.menuItemId + if (!id.match(/^map-inline/)) return - browser.tabs.sendMessage(tab.id, 'map-inline') + browser.tabs.sendMessage(tab.id, id) }) diff --git a/addon/index.mjs b/addon/index.mjs index b9fc349..e2fede3 100644 --- a/addon/index.mjs +++ b/addon/index.mjs @@ -1,8 +1,10 @@ +console.log('content script loaded') + browser.runtime.onMessage.addListener((message, sender, sendResponse) => { console.log('receive message', message) sendResponse('received') if (message === 'map-inline') { - alert('map') + alert('msg', message) return Promise.resolve('done') } return false -- cgit v1.2.3-70-g09d2