-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
36 lines (27 loc) · 860 Bytes
/
background.js
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
let menu = null
let link = null
chrome.runtime.onMessage.addListener (msg => {
if (msg.request === 'updateContextMenu') {
link = msg.link
if (!msg.text) {
if (menu) {
chrome.contextMenus.remove (menu.id)
menu = null
}
} else {
if (!menu) {
chrome.contextMenus.create (menu = {
id: 'mutko',
enabled: link ? true : false,
title: msg.text,
contexts: ['selection'],
onclick: () => {
chrome.tabs.create ({ url: link })
}
})
} else {
chrome.contextMenus.update (menu.id, { title: msg.text, enabled: link ? true : false })
}
}
}
})