-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
52 lines (42 loc) · 1.29 KB
/
options.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
var bg = chrome.extension.getBackgroundPage();
var mDivBlockList = document.getElementById("block_list");
var list = bg.mBlockList;
function appendToDiv(item){
var p = document.createElement('p');
var hostSpan = document.createElement('span');
hostSpan.innerHTML = item.host;
p.appendChild(hostSpan);
var countSpan = document.createElement('span');
countSpan.innerHTML = item.count;
p.appendChild(countSpan);
var blockSpan = document.createElement('span');
if(item.block){
blockSpan.innerHTML = '不屏蔽';
}else{
blockSpan.innerHTML = '屏蔽';
}
blockSpan.setAttribute("block",item.block);
blockSpan.setAttribute("url",item.host);
blockSpan.onclick = function(){
var url = this.getAttribute("url");
var isBlock = this.getAttribute("block");
console.log(isBlock);
if(isBlock == "true"){
console.log("remove");
bg.removeHostFromBlockList(url);
}else{
console.log("add");
bg.addUrlToBlockList(url);
}
console.log("click url = " + url);
};
p.appendChild(blockSpan);
mDivBlockList.appendChild(p);
}
for(var x in list){
appendToDiv({
host:x,
count:list[x].count,
block:list[x].block
});
}