1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

[bugfix] 解决右键菜单重复添加报错问题

This commit is contained in:
程序员小墨 2023-01-07 00:48:01 +08:00
parent 0620de4fa7
commit 0bdf1bf0df
2 changed files with 25 additions and 20 deletions

View File

@ -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"]
});
})
});
//

View File

@ -56,7 +56,6 @@ var manifest = {
// "automation": {},
"background": {
// "service_worker": "scripts/service_worker/background.js"
"service_worker": "background.js"
},