-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
36 lines (31 loc) · 860 Bytes
/
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
const body = document.body;
const onOff = document.querySelector("#isDark")
const Darkbtn = document.querySelector("#DarkBtn")
if (load("dark") == "On") Darkbtn.checked = true
else Darkbtn.checked = false
onOff.innerText = load("dark")
Darkbtn.addEventListener("click", changeDark)
function changeDark(event){
if (load("dark") == "Off"){
onOff.innerText = "On"
Darkbtn.checked = true
save("dark", "On")
}
else if (load("dark") == "On"){
onOff.innerText = "Off"
Darkbtn.checked = false
save("dark", "Off")
}
}
function save(item, coordsObj) {
localStorage.setItem(item, coordsObj);
}
function load(item) {
const loadedDark = localStorage.getItem(item);
if (loadedDark === null) {
save("dark", "Off")
return "Off"
} else {
return loadedDark
}
}