-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.js
32 lines (26 loc) · 1016 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
31
32
// In-page cache of the user's options
const options = {};
const optionsForm = document.getElementById("optionsForm");
// Immediately persist options changes
optionsForm.autodownload.addEventListener("change", (event) => {
options.autodownload = event.target.checked;
browser.storage.sync.set({options});
});
optionsForm.timeout.addEventListener("input", (event) => {
if (!event.target.value.match(/^\d{0,3}$/)) {
event.target.value = 30;
}
});
optionsForm.timeout.addEventListener("change", (event) => {
if (!event.target.value) event.target.value = 30;
options.timeout = event.target.value;
browser.storage.sync.set({options});
});
// Initialize the form with the user's option settings
if (typeof browser === "undefined") {
var browser = chrome;
}
const data = await browser.storage.sync.get("options");
Object.assign(options, data.options);
optionsForm.autodownload.checked = Boolean(options.autodownload);
optionsForm.timeout.value = Number(options.timeout || 30);