-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy paththeme-switcher.js
30 lines (27 loc) · 1.11 KB
/
theme-switcher.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
window.onload = function() {
var is_light;
var is_trans = false;
if (window.location.search == '?transdark') { is_light=false; is_trans=true; }
else if (window.location.search == '?translight') { is_light=true; is_trans=true; }
else if (window.location.search == '?dark') is_light=false;
else if (window.location.search == '?light') is_light=true;
else if (document.cookie == 'theme=dark') is_light=false;
else if (document.cookie == 'theme=light') is_light=true;
else is_light=false;
if (is_light) {
document.getElementsByTagName('html')[0].className = 'light';
}
if (is_trans) {
document.getElementsByTagName('html')[0].className += ' transparent';
} else {
var toggle = document.createElement('a');
toggle.className = 'themeSwitcher';
toggle.innerText = 'color';
toggle.onclick = function() {
is_light = !is_light;
document.cookie = 'theme='+(is_light?'light':'dark')+';path=/';
document.getElementsByTagName('html')[0].className = is_light?'light':'';
};
document.getElementsByTagName('body')[0].append(toggle);
}
}