-
Notifications
You must be signed in to change notification settings - Fork 4
/
background.ts
53 lines (48 loc) · 1.16 KB
/
background.ts
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
/** 定义右键菜单列表 */
const menuList: (chrome.contextMenus.CreateProperties & { action?(tab: chrome.tabs.Tab): void })[] = [
{
id: "issue",
title: "Issues & 需求",
contexts: ["action"],
action() {
chrome.tabs.create({
url: "https://github.com/Dolov/chrome-github-2fa/issues"
})
}
},
{
id: "source",
title: "查看源码",
contexts: ["action"],
action() {
chrome.tabs.create({
url: "https://github.com/Dolov/chrome-github-2fa"
})
}
},
{
id: "document",
title: "使用文档",
contexts: ["action"],
action() {
chrome.tabs.create({
url: "https://github.com/Dolov/chrome-github-2fa/issues/1"
})
}
},
]
/** 创建右键菜单 */
menuList.forEach(item => {
const { action, ...menuProps } = item
chrome.contextMenus.create(menuProps);
})
/** 监听右键菜单的点击事件,执行对应的行为 */
chrome.contextMenus.onClicked.addListener((info, tab) => {
const { menuItemId } = info
const menu = menuList.find(item => item.id === menuItemId)
if (!menu) return
const { action } = menu
action && action(tab)
});
export {
}