-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
30 lines (29 loc) · 990 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
let activeTabs = {};
chrome.action.onClicked.addListener(function(tab) {
console.log('deactivated clicked')
if (activeTabs[tab.id]) {
console.log('Deactivating')
chrome.tabs.sendMessage(tab.id, { action: 'deactivate' });
delete activeTabs[tab.id];
chrome.action.setIcon({tabId: tab.id, path: {
"16": "icon-24.png",
"48": "icon-48.png",
"128": "icon-96.png"
}});
} else {
console.log('deactivated')
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["content.js"]
}, () => {
console.log('Activating');
activeTabs[tab.id] = true;
chrome.tabs.sendMessage(tab.id, { action: 'activate' });
chrome.action.setIcon({tabId: tab.id, path: {
"16": "active-icon-24.png",
"48": "active-icon-48.png",
"128": "active-icon-96.png"
}});
});
}
});