-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.js
59 lines (54 loc) · 1.9 KB
/
code.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
// const themeSwitch = document.querySelector('.theme-switch');
// themeSwitch.checked = localStorage.getItem('switchedTheme') === 'true';
// const switcher = document.querySelector('.theme-button');
// switcher.addEventListener('click', function() {
// document.body.classList.set('dark-theme');
// document.body.classList.set('light-theme');
// const className = document.body.className;
// if(className == "light-theme") {
// this.textContent = "Dark";
// } else if (className == "dark-theme") {
// this.textContent = "Light";
// } else if (className == "") {
// this.textContent = "Error";
// }else {
// this.textContent = "kut";
// }
// console.log('Current theme: ' + className);
// });
// function themeSwitcher() {
// var element = document.getElementById("mainBody");
// // const className = document.body.className;
// if(element == "light-theme") {
// this.textContent = "Dark";
// document.body.classList.toggle("dark-theme");
// } else if (element == "dark-theme") {
// this.textContent = "Light";
// document.body.classList.toggle("light-theme");
// } else {
// this.textContent = "dark";
// document.body.classList.toggle("dark-theme");
// }
// }
// function to set a given theme/color-scheme
function setTheme(themeName) {
localStorage.setItem('theme', themeName);
document.documentElement.className = themeName;
}
// function to toggle between light and dark theme
function toggleTheme() {
if (localStorage.getItem('theme') === 'theme-dark'){
setTheme('theme-light');
} else {
setTheme('theme-dark');
}
}
// Immediately invoked function to set the theme on initial load
(function () {
if (localStorage.getItem('theme') === 'theme-dark') {
setTheme('theme-dark');
} else {
setTheme('theme-light');
}
})();