forked from ikakonbu/Misskey-TL-Filter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserviceworker.js
53 lines (45 loc) · 1.26 KB
/
serviceworker.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
chrome.action.disable();
chrome.action.setIcon({path:"icon_disable.png"});
chrome.tabs.onUpdated.addListener((tabId, changeinfo, tab) => {
if(changeinfo.status == "complete"){
CheckURL(tab);
}
});
chrome.tabs.onActivated.addListener((result) => {
chrome.tabs.get(result.tabId, (tab) => {
CheckURL(tab);
})
});
/*check url and enable tabid's tab popup
when url is misskey.io or user seted url*/
function CheckURL(tab){
let uri = new URL(tab.url);
/*check default setting*/
if(uri.hostname.indexOf('misskey.io') != -1){
setpopupstate(tab.id, true);
return;
} else {
setpopupstate(tab.id, false);
}
/*check user setting*/
chrome.storage.local.get(["setting1"]).then((result) => {
if(result.setting1){
let urls = result.setting1.split(',');
for(let url of urls){
if(uri.hostname.indexOf(url) != -1){
setpopupstate(tab.id, true);
return;
}
}
}
});
}
function setpopupstate(tabid, flag){
if(flag){
chrome.action.enable(tabid);
chrome.action.setIcon({path:"icon_48.png"});
} else {
chrome.action.disable(tabid);
chrome.action.setIcon({path:"icon_disable.png"});
}
}