-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
33 lines (30 loc) · 855 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
let executed = new Set();
chrome.tabs.onActivated.addListener(function(tab) {
const tabId = tab.tabId;
chrome.tabs.sendMessage(tabId, {action: 'echo'}, (res) => {
if (res) {
executed.add(tabId);
} else {
executed.delete(tabId);
}
});
});
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo) {
if (changeInfo.status === 'loading') {
chrome.tabs.sendMessage(tabId, {action: 'echo'}, (res) => {
if (res) {
executed.add(tabId);
} else {
executed.delete(tabId);
}
});
}
});
chrome.browserAction.onClicked.addListener(function(tab) {
if (!executed.has(tab.id)) {
chrome.tabs.executeScript(tab.id, {file: 'content.js'});
chrome.tabs.insertCSS(tab.id, {file: 'content.css'});
executed.add(tab.id);
}
chrome.tabs.sendMessage(tab.id, {action: 'toggle'});
});