-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
176 lines (116 loc) · 3.81 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
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
var numoptions = 70;
function initialize() {
chrome.storage.sync.get("notloaded", function(val) {
//console.log("loadStorage: " + val.notloaded + " received from " + "notloaded" + ".");
var notLoaded = JSON.parse(val.notloaded);
//console.log(notLoaded);
if (notLoaded) {
var bool = JSON.stringify(false);
chrome.storage.sync.set({"notloaded": bool}, function() {
//console.log("saveStorage: " + bool + " saved in " + "notloaded" + ".");
});
saveStorage("notloaded", false);
var newloat = [1,3,70,7,10];
var loat = JSON.stringify(newloat);
chrome.storage.sync.set({"loatstorage": loat}, function() {
//console.log("saveStorage: " + loat + " saved in " + "loatstorage" + ".");
});
saveStorage("loatstorage", newloat);
populate();
} else {
chrome.storage.sync.get("lossearch", function(val) {
//console.log("loadStorage: " + val.lossearch + " received from " + "lossearch" + ".");
var los = JSON.parse(val.lossearch);
updateLocal(los);
populate();
});
}
});
}
function populate() {
var loat = loadStorage("loatstorage");
for (var i = 1; i <= numoptions; i++) {
var alreadyThere = isAlreadyThere(i, loat);
if (alreadyThere) { document.getElementById("l"+i).checked = true; }
}
}
function updateLocal (array) {
var newlos = new Array(array.length);
var newloat = new Array(array.length);
for(var i = 0; i < array.length; i++) {
newlos[i] = new Array(4);
newlos[i] = array[i].slice(0);
newloat[i] = newlos[i][1];
}
sortAndSave("lossearch", newlos, "loatstorage", newloat);
}
function isAlreadyThere(index, array) {
return array.indexOf(index) == -1? false : true;
}
function add(index) {
var x = index;
var loat = loadStorage("loatstorage");
loat.push(x);
var parsedArray = loadStorage("lossearch");
var newoptions = new Array(parsedArray.length+1);
for(var i = 0; i < parsedArray.length; i++) {
newoptions[i] = new Array(4);
newoptions[i] = parsedArray[i].slice(0);
}
var nname = document.getElementById("name"+x).value;
var nlink = document.getElementById("link"+x).value;
newoptions[i] = new Array(4);
newoptions[i][0] = "-1";
newoptions[i][1] = x;
newoptions[i][2] = nname;
newoptions[i][3] = nlink;
sortAndSave("lossearch", newoptions, "loatstorage", loat);
}
function remove(index) {
document.getElementById("l"+index).checked = false;
var loat = loadStorage("loatstorage");
var x = loat.indexOf(index);
loat.splice(x, 1);
var parsedArray = loadStorage("lossearch")
parsedArray.splice(x, 1)
var newoptions = new Array(loat.length);
for(var i = 0; i < parsedArray.length; i++) {
newoptions[i] = new Array(4);
newoptions[i] = parsedArray[i].slice(0);
}
sortAndSave("lossearch", newoptions, "loatstorage", loat);
}
function removeWindow () {
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.update(tab.id, { selected: true } )
});
}
function addFromList() {
var loat = loadStorage("loatstorage");
for (var i = 1; i <= numoptions; i++) {
var alreadyThere = isAlreadyThere(i, loat);
if (document.getElementById("l"+i).checked && !alreadyThere) { add(i); }
if (!document.getElementById("l"+i).checked && alreadyThere) { remove(i); }
saveOptions();
}
var status = document.getElementById("status_addfromlist");
status.innerHTML = "Options Saved.";
setTimeout(function() {status.innerHTML = ""; window.close()},1250);
}
function onLoad() {
var button;
var table;
for (var i = 1; i <= 15; i++) {
button = document.getElementById("header"+i);
table = document.getElementById("table"+i);
image = document.getElementById("t"+i);
hideShow(button, table, image);
}
}
document.addEventListener("DOMContentLoaded", function () {
setTimeout(function () {
document.getElementById("save").addEventListener("click", addFromList)
}, 2000)
});
initialize();
onLoad();