-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
30 lines (24 loc) · 809 Bytes
/
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
function saveOptions(e) {
e.preventDefault();
browser.storage.sync.set({
newtab: document.querySelector("#newtab").value,
count: document.querySelector("#count").value
});
}
function restoreOptions() {
function setNewTab(result) {
document.querySelector("#newtab").value = result.newtab || "false";
}
function setCount(result) {
document.querySelector("#count").value = result.count || "true";
}
function onError(error) {
console.log(`Error: ${error}`);
}
const newtab = browser.storage.sync.get("newtab");
newtab.then(setNewTab, onError);
const count = browser.storage.sync.get("count");
count.then(setCount, onError);
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);