-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoptions.js
35 lines (29 loc) · 1.06 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
function saveOptions(e) {
e.preventDefault();
browser.storage.local.set({
hussiecomment: document.querySelector("#hussiecomment").checked,
notuhc: document.querySelector("#notuhc").checked,
});
}
function restoreOptions() {
function setCurrentChoice(key) {
return async function setCurrentChoice(result) {
if (result[key] === undefined) {
options = {}
options[key] = true
await browser.storage.local.set(options);
}
document.querySelector("#" + key).checked = result[key];
}
}
function onError(error) {
console.log('[HOMESTUCK COMPANION] Error saving options: ${error}');
}
//We attempt to get the boolean values from storage
var hussiecomment = browser.storage.local.get("hussiecomment");
var notuhc = browser.storage.local.get("notuhc");
hussiecomment.then(setCurrentChoice("hussiecomment"), onError);
notuhc.then(setCurrentChoice("notuhc"), onError);
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);