forked from magicoflolis/Userscript-Plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
25 lines (23 loc) · 783 Bytes
/
Copy pathoptions.js
File metadata and controls
25 lines (23 loc) · 783 Bytes
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
const brws = typeof browser === "undefined" ? chrome : browser;
brws.storage.local.get((storedConfig) => {
($form = document.querySelector("form") ?? console.log(`[UserJS] can't find ${target}`)),
(config = {
theme: "dark",
sleazyfork: false,
...storedConfig,
});
for (let prop in config) {
prop in $form.elements
? $form.elements[prop].type == "checkbox"
? ($form.elements[prop].checked = config[prop])
: ($form.elements[prop].value = config[prop])
: false;
}
$form.addEventListener("change", (e) => {
let $el = /** @type {HTMLInputElement} */ (e.target);
$el.type == "checkbox"
? (config[$el.name] = $el.checked)
: (config[$el.name] = $el.value);
brws.storage.local.set(config);
});
});