2020-09-27 19:21:23 -05:00
|
|
|
// Store the theme
|
2020-08-30 01:08:03 -05:00
|
|
|
let darkTheme = localStorage.getItem('darkTheme');
|
|
|
|
const themeToggle = document.querySelector('#themeButton');
|
2020-08-29 22:47:08 -05:00
|
|
|
|
2020-08-30 01:08:03 -05:00
|
|
|
const enableDark = () => {
|
2020-08-30 01:32:40 -05:00
|
|
|
document.body.classList.add('darktheme');
|
|
|
|
localStorage.setItem('darkTheme', 'enabled');
|
|
|
|
themeToggle.innerHTML = `<i id="bicon" data-feather="moon"></i>`;
|
|
|
|
feather.replace();
|
|
|
|
};
|
|
|
|
|
|
|
|
const disableDark = () => {
|
|
|
|
document.body.classList.remove('darktheme');
|
|
|
|
localStorage.setItem('darkTheme', null);
|
|
|
|
themeToggle.innerHTML = `<i id="bicon" data-feather="sun"></i>`;
|
|
|
|
feather.replace();
|
|
|
|
};
|
|
|
|
|
|
|
|
if (darkTheme === 'enabled') {
|
|
|
|
enableDark();
|
|
|
|
} else {
|
|
|
|
disableDark();
|
2020-08-29 22:47:08 -05:00
|
|
|
}
|
2020-08-30 01:08:03 -05:00
|
|
|
|
|
|
|
themeToggle.addEventListener('click', () => {
|
2020-08-30 01:32:40 -05:00
|
|
|
darkTheme = localStorage.getItem('darkTheme');
|
|
|
|
if (darkTheme !== 'enabled') {
|
|
|
|
enableDark();
|
|
|
|
} else {
|
|
|
|
disableDark();
|
|
|
|
}
|
2020-08-30 01:08:03 -05:00
|
|
|
});
|
2020-10-16 21:10:55 +06:00
|
|
|
|
|
|
|
const today = new Date();
|
|
|
|
const Hr = today.getHours();
|
|
|
|
|
|
|
|
if (Hr >= 19 || Hr < 5) {
|
|
|
|
enableDark();
|
|
|
|
} else {
|
|
|
|
disableDark();
|
2020-10-16 21:13:00 +06:00
|
|
|
}
|