-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoptions.js
More file actions
42 lines (38 loc) · 1.19 KB
/
options.js
File metadata and controls
42 lines (38 loc) · 1.19 KB
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
"use strict";
const {storage} = browser;
async function saveOptions(e) {
let result = await storage.local.get("enabled_file_exts");
if (e.target.checked) {
if (result.hasOwnProperty("enabled_file_exts")) {
result["enabled_file_exts"].push(e.target.id);
storage.local.set({
"enabled_file_exts": result["enabled_file_exts"],
});
}
else {
storage.local.set({
"enabled_file_exts": [e.target.id],
});
}
}
else {
if (result.hasOwnProperty("enabled_file_exts")) {
storage.local.set({
"enabled_file_exts": result["enabled_file_exts"].filter(fileExt => fileExt != e.target.id),
});
}
}
}
async function restoreOptions(e) {
let checkboxes = document.querySelectorAll('input[type="checkbox"]');
for (let checkbox of checkboxes) {
checkbox.addEventListener("click", saveOptions);
}
let results = await storage.local.get(null);
if (results.hasOwnProperty("enabled_file_exts")) {
for (let checkbox of checkboxes) {
checkbox.checked = results["enabled_file_exts"].includes(checkbox.id);
}
}
}
document.addEventListener("DOMContentLoaded", restoreOptions);