-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoptions.js
48 lines (47 loc) · 1.73 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function save_options() {
const selectedFlow = document.getElementById("flow").value;
const copyWithCommand = document.getElementById("copy-with-command").checked;
const regexpExclude = {
pattern: document.getElementById("regexp-exclude-pattern").value,
flag: document.getElementById("regexp-exclude-flag").value,
};
const registry = {
key: document.getElementById("key-registry").value,
name: document.getElementById("name-registry").value,
};
chrome.storage.sync.set(
{
selectedFlow,
copyWithCommand,
regexpExclude,
registry,
},
() => {
const save = document.getElementById("save");
save.textContent = "Option saved";
setTimeout(() => {
save.textContent = "Save";
}, 3500);
}
);
}
function restore_options() {
chrome.storage.sync.get(
["selectedFlow", "copyWithCommand", "regexpExclude", "registry"],
(options) => {
document.getElementById("flow").value = options.selectedFlow || "simple";
document.getElementById("copy-with-command").checked =
options.copyWithCommand || false;
document.getElementById("regexp-exclude-pattern").value =
(options.regexpExclude && options.regexpExclude.pattern) || "";
document.getElementById("regexp-exclude-flag").value =
(options.regexpExclude && options.regexpExclude.flag) || "";
document.getElementById("key-registry").value =
(options.registry && options.registry.key) || "default";
document.getElementById("name-registry").value =
(options.registry && options.registry.name) || "default";
}
);
}
document.addEventListener("DOMContentLoaded", restore_options);
document.getElementById("save").addEventListener("click", save_options);