-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
46 lines (42 loc) · 1.47 KB
/
background.js
File metadata and controls
46 lines (42 loc) · 1.47 KB
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
async function handleMsg(request, sender, sendResponse) {
console.log("*** function handleMsg: request ", request)
console.log("*** function handleMsg: sender ", sender)
console.log("*** function handleMsg: sendResponse", sendResponse)
await browser.contextMenus.removeAll()
request.forEach(e => {
browser.contextMenus.create({
id: e,
title: e,
contexts: ['page']
})
})
}
browser.runtime.onMessage.addListener(handleMsg)
browser.browserAction.onClicked.addListener(async function (tab) {
console.log("*** function browserAction.onClicked: tab", tab)
const config = await browser.storage.local.get("enabled")
console.log(config)
console.log("enabled", config.enabled)
if (config.enabled) {
browser.browserAction.setIcon({
path: "icons/agora-disabled.png",
tabId: tab.id
})
browser.storage.local.set({
enabled: false
})
} else {
browser.browserAction.setIcon({
path: "icons/agora.png",
tabId: tab.id
})
browser.storage.local.set({
enabled: true
})
}
})
browser.contextMenus.onClicked.addListener(async function (info, tab) {
const config = await browser.storage.local.get("agora")
console.log("info", info.menuItemId)
let newTab = await browser.tabs.create({ 'active': true, 'url': `${config.agora}/${info.menuItemId}`, 'index': tab.index + 1 });
});