-
Notifications
You must be signed in to change notification settings - Fork 0
/
popupscript.js
78 lines (55 loc) · 1.57 KB
/
popupscript.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var URLpath
var URLlist = []
chrome.tabs.query(
{
active:true
},
tabs=>{
URLpath = tabs[0].url;
let domain = (new URL(URLpath))
URLpath = domain.hostname
}
)
chrome.storage.local.get(["blockedlist"], function(items){
console.log("Existing List = ", JSON.stringify(items))
URLlist = items["blockedlist"]
if(typeof URLlist === "undefined"){
URLlist = []
chrome.storage.local.set({ "blockedlist": URLlist }, function(){
});
}
});
window.onload = function(){
const by = document.getElementById("buttonyes")
if(by){
by.addEventListener("click", clickedyes);
}
const bn = document.getElementById("buttonno")
if(bn){
bn.addEventListener("click", clickedno);
}
}
function clickedyes(){
URLlist.push(URLpath)
URLlist = [...new Set(URLlist)];
chrome.storage.local.set({ "blockedlist": URLlist }, function(){
});
chrome.storage.local.get(["blockedlist"], function(items){
console.log("New (Added) List = ", JSON.stringify(items))
});
chrome.tabs.reload()
window.close()
}
function clickedno(){
var URLlistindex = URLlist.indexOf(URLpath);
if(URLlistindex != -1)
URLlist.splice(URLlistindex, 1)
URLlist = [...new Set(URLlist)];
chrome.storage.local.set({ "blockedlist": URLlist }, function(){
});
chrome.storage.local.get(["blockedlist"], function(items){
console.log("New (Removed) List = ", JSON.stringify(items))
});
chrome.tabs.reload()
window.close();
}