-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
47 lines (43 loc) · 1.09 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
var checkbox1 = document.getElementById("checkbox1");
var checkbox2 = document.getElementById("checkbox2");
var threshold1 = document.getElementById("threshold1");
var threshold2 = document.getElementById("threshold2");
function setCheckboxStorageValue(el) {
const options = {};
options[el.id] = el.checked;
chrome.storage.sync.set(options);
}
function setTextStorageValue(el) {
const options = {};
options[el.id] = el.value;
chrome.storage.sync.set(options);
}
[checkbox1, checkbox2].forEach((it) => {
let el = it;
let id = el.id;
chrome.storage.sync.get(id, function (data) {
el.checked = data[id];
});
el.addEventListener("change", function () {
setCheckboxStorageValue(el);
});
});
[threshold1, threshold2].forEach((it) => {
let el = it;
let id = el.id;
chrome.storage.sync.get(id, function (data) {
el.value = data[id];
});
el.addEventListener("change", function () {
if (isNaN(el.value)) {
el.value = 25;
}
if (el.value < 0) {
el.value = 0;
}
if (el.value > 99) {
el.value = 99;
}
setTextStorageValue(el);
});
});