-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
34 lines (27 loc) · 1.05 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
function saveOptions(e) {
e.preventDefault();
browser.storage.sync.set({
duringShow: document.querySelector("#duringShow").checked,
whileBrowsing: document.querySelector("#whileBrowsing").checked
});
}
function restoreOptions() {
function setCurrentChoice(settings) {
if (settings.duringShow == null) {
settings.duringShow = true;
}
if (settings.whileBrowsing == null) {
settings.whileBrowsing = false;
}
document.querySelector("#duringShow").checked = settings.duringShow;
document.querySelector("#whileBrowsing").checked = settings.whileBrowsing;
}
function onError(error) {
console.error(`Spoilern't: ${error}`);
}
var getting = browser.storage.sync.get();
getting.then(setCurrentChoice, onError);
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("#duringShow").addEventListener("change", saveOptions);
document.querySelector("#whileBrowsing").addEventListener("change", saveOptions);