-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
61 lines (42 loc) · 1.27 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
51
52
53
54
55
56
57
58
59
60
61
var save = function() {
var subjects = document.getElementsByClassName("subject");
var subjects_names = [];
for(var i = 0; i < subjects.length; i++){
if(subjects[i].value){
subjects_names.push(normalize(subjects[i].value))
}
}
chrome.storage.sync.set({
hide : subjects_names
});
};
var add = function (value) {
var p = document.createElement("p");
p.style.margin = "2px";
var input = document.createElement("input");
input.type = "text";
input.className = "subject";
if(typeof value == "string"){
input.value = value;
}
p.appendChild(input);
document.getElementById("subjects").appendChild(p);
};
var restore_options = function () {
chrome.storage.sync.get("hide", function (item) {
if(item.hide){
for(var i = 0; i < item.hide.length; i++){
add(item.hide[i]);
}
}
else{
add();
}
});
};
var normalize = function(string){
return string.replace( /[^-A-Za-z0-9]+/g, '-' ).toLowerCase();
};
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click', save);
document.getElementById('add').addEventListener('click', add);