-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpopup.js
101 lines (81 loc) · 2.11 KB
/
popup.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
// Github: https://github.com/pmsosa
//Add Item Button Action
function additem(){
console.log("adding...");
newitem = document.getElementById("newitem").value;
if (newitem.length <= 2){
return
}
if (newitem.value != ""){
chrome.extension.getBackgroundPage().addblacklist(newitem);
fill_blacklist();
document.getElementById("newitem").value = "";
}
else{
newitem.focus();
}
}
//Remove Item Button Action
function rmitem(){
console.log("rming...");
newitem = itemlist.value;
if (newitem != ""){
chrome.extension.getBackgroundPage().removeblacklist(newitem,fill_blacklist);
rmbtndisable()
}
else{
itemlist.focus();
}
}
//Remove Button Disabling
function rmbtndisable(){
if (itemlist.value == ""){
btrm.disabled = true;
}
else{
btrm.disabled = false;
}
}
//Fills the Blacklist with the Filtered Keywords
function fill_blacklist(){
itemlist.innerHTML = ""
bl = chrome.extension.getBackgroundPage().blacklist;
if (bl != []){
for (i = 0; i < bl.length; i++){
var opt = document.createElement("option");
opt.value = bl[i];
opt.innerHTML = bl[i];
itemlist.appendChild(opt);
}
}
}
//Show Instructions
function showInstructions(){
chrome.tabs.create({
url: chrome.extension.getURL("index.html")
});
}
//Run this when you load!
document.addEventListener('DOMContentLoaded', function () {
var btadd = document.getElementById("btadd");
var btrm = document.getElementById("btrm");
var itemlist = document.getElementById("itemlist");
var instr = document.getElementById("instr");
btadd.addEventListener('click',additem);
btrm.addEventListener('click',rmitem);
itemlist.addEventListener('change',rmbtndisable);
instr.addEventListener('click',showInstructions);
btrm.disabled = true;
fill_blacklist();
//Key Bindings to make the Extension a bit more user friendly
document.addEventListener("keydown", function(e){
if(e.keyCode === 13 && document.activeElement.id == 'newitem') {
additem();
}
if(e.keyCode === 8 || e.keyCode === 46) {
if (document.activeElement.id == 'itemlist' && btrm.disabled === false){
rmitem();
}
}
});
});