-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
39 lines (35 loc) · 935 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
33
34
35
36
37
38
39
function el(id) {
return document.getElementById(id)
}
document.addEventListener("DOMContentLoaded", () => {
loadOptions()
el("enableClock").addEventListener("click", saveOptions)
el("color").addEventListener("keypress", (e) => {
if (e.keyCode === 13) { // enter key
saveOptions()
}
})
})
function loadOptions() {
chrome.storage.sync.get({
clockEnabled: true,
color: "",
}, (opt) => {
el("enableClock").checked = opt.clockEnabled
el("color").value = opt.color
})
}
function saveOptions() {
console.log("hello")
chrome.storage.sync.set({
clockEnabled: el("enableClock").checked,
color: el("color").value,
}, () => {
const status = el("status")
status.textContent = "Saved"
status.style.opacity = 1
setTimeout(() => {
status.style.opacity = 0
}, 2000)
})
}