-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
33 lines (27 loc) · 933 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 extState = false;
let current_tab_id;
chrome.tabs.onActivated.addListener(tab => {
chrome.tabs.get(tab.tabId, current_tab_info => {
current_tab_id = tab.tabId;
})
});
function pocketSat(tab) {
if(extState && (tab === current_tab_id)){
chrome.tabs.insertCSS(null, {file: './styles.css'})
chrome.tabs.executeScript(null, {file: './foreground.js'}, ()=> console.log('foreground injected'))
}
}
chrome.tabs.onUpdated.addListener(pocketSat);
chrome.extension.onMessage.addListener(
function (request) {
if (request.message == "turnOnExt") {
extState = true;
chrome.tabs.insertCSS(null, {file: './styles.css'})
chrome.tabs.executeScript(null, {file: './foreground.js'})
chrome.tabs.sendMessage(current_tab_id, 'append-child');
}
else if (request.message == "turnOffExt") {
chrome.tabs.sendMessage(current_tab_id, 'unappend-child');
extState = false;
}
})