blob: 889b0dde2d592d3b5cb364304bf534f504932081 (
plain)
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
|
var theme_switch = document.getElementById("dark-light-switch");
var body = document.getElementsByTagName("BODY")[0];
function init( color ){
theme_switch.setAttribute("color", color);
document.getElementById("dark-light-switch");
}
function change(color){
window.setTimeout(function() {
document.documentElement.classList.remove('color-theme-in-transition')
}, 1000)
document.documentElement.classList.add('color-theme-in-transition');
document.documentElement.setAttribute('data-theme', color);
theme_switch.setAttribute("color", color);
}
function theme_changed(){
color = theme_switch.getAttribute("color");
if(color=="light")
change("dark");
else
change("light");
}
var background = getComputedStyle(body).getPropertyValue("background-color");
if(background == "rgb(255, 255, 255)") {
init("light");
} else {
init("dark");
}
theme_switch.addEventListener("click", theme_changed);
theme_switch.addEventListener("touch", theme_changed);
|