-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
61 lines (46 loc) · 1.6 KB
/
popup.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import con, {init as initCon} from "/console.js";
import {handle, remote} from "/message.js";
const submitButtons = document.querySelectorAll("button");
let forId = null;
document.getElementById("sort-form").addEventListener("submit", (e) => {
e.preventDefault();
const data = new FormData(e.target);
const conf = {};
for (const [key, value] of data.entries()) conf[key] = value;
for (const b of submitButtons) b.disabled = true;
remote.sort(forId, conf);
});
document.getElementById("reset-form").addEventListener("submit", (e) => {
e.preventDefault();
remote.sort(forId, null);
});
handle({
sortInProgress(value) {
for (const b of submitButtons) b.disabled = value;
},
});
(async () => {
await initCon();
const {conf, node} = await remote.popupOpened();
con.log("Loaded config:", conf);
if (node) {
con.log("Node-specific:", node);
const {id, title} = node;
const context = document.getElementById("context");
context.textContent = `Sorting "${title || id}"`;
const elems = document.getElementsByClassName("node-specific");
for (const elem of elems) elem.style.display = "block";
forId = id;
}
for (const [key, value] of Object.entries(conf)) {
const elems = document.querySelectorAll(`[name="${key}"]`);
if (elems.length === 0) {
con.warn("No matching elements:", key);
continue;
}
for (const elem of elems) {
if ("checked" in elem) elem.checked = elem.value === value;
else elem.value = value;
}
}
})();