-
Notifications
You must be signed in to change notification settings - Fork 0
/
black_list.js
207 lines (130 loc) · 4.27 KB
/
black_list.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
///---------Include list_tools.js------------------------------
function Link(url) {
this.url = url;
this.hits = 0;
}
function findMatchingLink(url, list) {
var target = findMatchingLinkIndex(url, list);
if(target != -1) { return list[target]; }
else return null;
}
function findMatchingLinkIndex(url, list) {
if(list == null) { return -1; }
for (var i = 0; i < list.length; i++) {
if (url.indexOf(list[i].url) != -1) {
return i; }
}
return -1;
}
//specialized
function removeMatchingLink(url, list) {
// var target = findMatchingLinkIndex(url, list);
// if(target != -1) { list.splice(target, 1); }
if(list == null) { return false; }
for (var i = 0; i < list.length; i++) {
if (url == list[i].url) {
list.splice(i, 1);
return true;
}
}
return false;
}
///---------------------------------------------------------------
var black_btn;
var a_btn;
window.onload = function(e){
black_btn = document.getElementById("black_list_btn");
black_btn.onclick = function() {
console.log("hey");
black_btn.className = "button_on";
a_btn.className = "";
document.getElementById("the_a_list").style.display = "none";
document.getElementById("the_black_list").style.display = "block";
}
a_btn = document.getElementById("a_list_btn");
a_btn.onclick = function() {
console.log("hey");
a_btn.className = "button_on";
black_btn.className = "";
document.getElementById("the_a_list").style.display = "block";
document.getElementById("the_black_list").style.display = "none";
}
document.getElementById('blam_add_me').onkeypress=function(e){
console.log("HEYHE");
if(e.keyCode==13){
document.getElementById('blam_add_item').click();
}
}
var addBtn = document.getElementById("blam_add_item");
addBtn.onclick = function() {
var add_me_input = document.getElementById("blam_add_me");
var url = add_me_input.value;
var link = new Link(url);
black_list.push(link);
chrome.storage.local.set({ 'black_list' : black_list }, function() {});
addItem(url, black_list);
}
document.getElementById('highlight_add_me').onkeypress=function(e){
if(e.keyCode==13){
document.getElementById('highlight_add_item').click();
}
}
var addBtn = document.getElementById("highlight_add_item");
addBtn.onclick = function() {
var add_me_input = document.getElementById("highlight_add_me");
var url = add_me_input.value;
var link = new Link(url);
a_list.push(link);
chrome.storage.local.set({ 'a_list' : a_list }, function() {});
addItem(url, a_list);
}
}
var black_list;
chrome.storage.local.get('black_list', function(result) {
black_list = result.black_list;
displayList(black_list);
});
var a_list;
chrome.storage.local.get('a_list', function(result) {
a_list = result.a_list;
displayList(a_list);
});
function displayList(list) {
for(var i = 0; i < list.length; i++) {
var url = list[i].url;
addItem(url, list);
}
}
function addItem(url, list) {
var item = document.createElement("DIV");
item.name = url;
var button = document.createElement("BUTTON");
button.innerHTML = "-";
button.name = url;
button.className = "unblock_item";
item.appendChild(button);
var span = document.createElement("SPAN");
span.innerHTML = url;
if(list == a_list) {
span.className = "good_link"; }
item.appendChild(span);
item.innerHTML += "<br>";
if(list == black_list) {
var add_me = document.getElementById("blam_add_me");
add_me.parentNode.insertBefore(item, add_me.nextSibling); }
else if(list == a_list) {
var add_me = document.getElementById("highlight_add_me");
add_me.parentNode.insertBefore(item, add_me.nextSibling); }
var buttons = item.getElementsByTagName("BUTTON");
buttons[0].onclick = function() {
var link = this.name;
console.log(link);
removeMatchingLink(link, list);
if(list == black_list) {
chrome.storage.local.set({ 'black_list' : list }, function() {}); }
if(list == a_list) {
chrome.storage.local.set({ 'a_list' : list }, function() {}); }
var container = this.parentNode;
container.parentNode.removeChild(container);
}
}