-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (30 loc) · 1008 Bytes
/
script.js
File metadata and controls
32 lines (30 loc) · 1008 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
26
27
28
29
30
31
32
var checkbox = document.querySelector('input[name=mode]');
var data = document.getElementById("myForm");
window.onload = () => {
console.log(checkbox.value)
if (checkbox.value == "On" || checkbox.checked == true) {
document.documentElement.setAttribute('data-theme', 'dark')
checkbox.checked = true
checkbox.value = "On"
}
else {
document.documentElement.setAttribute('data-theme', 'light')
checkbox.checked = false
checkbox.value = "Off"
}
console.log("load success")
}
checkbox.addEventListener('change', function() {
var theme = this.checked ? 'dark' : 'light';
this.value = this.checked ? "On" : "Off";
trans()
document.documentElement.setAttribute('data-theme', theme)
console.log("is " + this.value)
data.submit()
})
let trans = () => {
document.documentElement.classList.add('transition');
window.setTimeout(() => {
document.documentElement.classList.remove('transition');
}, 1000)
}