From 0bdf1bf0df3ecbcf87f98c3dda5c7fab83c0e56c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Sat, 7 Jan 2023 00:48:01 +0800 Subject: [PATCH] =?UTF-8?q?[bugfix]=20=E8=A7=A3=E5=86=B3=E5=8F=B3=E9=94=AE?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E9=87=8D=E5=A4=8D=E6=B7=BB=E5=8A=A0=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- background.js | 44 +++++++++++++++++++++++++------------------- generate-manifest.js | 1 - 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/background.js b/background.js index 1d2cd5d..f440d30 100644 --- a/background.js +++ b/background.js @@ -2,35 +2,41 @@ console.clear() console.log("[小墨助手]", "Service Worker init success.") -/** - * 右键菜单 - */ -chrome.contextMenus.create({ - id: 'bitdance', - title: '小墨助手' -}) -chrome.contextMenus.create({ - id: 'bitdance-advanced-search', - title: '高级搜索', - parentId: 'bitdance', - // onclick: function (info) { - // } -}) -chrome.contextMenus.onClicked.addListener(function (info) { - console.log('当前菜单信息:' + JSON.stringify(info)) - console.log("[小墨助手]", "高级搜索 已点击菜单") -}) // Events must be registered synchronously from the start of the page. chrome.runtime.onInstalled.addListener(() => { console.log("[小墨助手]", "chrome.runtime.onInstalled.") + + // In Chrome, you should create the context menu just once after install/update. + // refer: https://stackoverflow.com/questions/64318529/cannot-create-item-with-duplicate-context-menu-id-in-extension + + /** + * 右键菜单 + */ + chrome.contextMenus.create({ + id: 'bitdance', + title: '小墨助手' + }) + + chrome.contextMenus.create({ + id: 'bitdance-advanced-search', + title: '高级搜索', + parentId: 'bitdance', + // onclick: function (info) { + // } + }) + chrome.contextMenus.onClicked.addListener(function (info) { + console.log('当前菜单信息:' + JSON.stringify(info)) + console.log("[小墨助手]", "高级搜索 已点击菜单") + }) + chrome.contextMenus.create({ "id": "sampleContextMenu", "title": "Sample Context Menu", "contexts": ["selection"] - }); + }) }); // diff --git a/generate-manifest.js b/generate-manifest.js index 6b3a997..5f0f437 100644 --- a/generate-manifest.js +++ b/generate-manifest.js @@ -56,7 +56,6 @@ var manifest = { // "automation": {}, "background": { - // "service_worker": "scripts/service_worker/background.js" "service_worker": "background.js" },