2021-07-18 10:34:01 +02:00
|
|
|
window.addEventListener('DOMContentLoaded', function () {
|
|
|
|
const light = '🌝', dark = '🌚';
|
|
|
|
const LIGHT = 'light', DARK = 'dark';
|
|
|
|
const themeSwitcher = document.getElementById('theme-switcher');
|
|
|
|
|
|
|
|
themeSwitcher.innerHTML = localStorage.theme === LIGHT ? light : dark;
|
|
|
|
|
|
|
|
themeSwitcher.addEventListener('click', function () {
|
|
|
|
const currentTheme = localStorage.theme,
|
|
|
|
newTheme = currentTheme === LIGHT ? DARK : LIGHT,
|
|
|
|
{ classList } = document.querySelector('html'),
|
|
|
|
text = newTheme === LIGHT ? light : dark;
|
|
|
|
classList.remove(currentTheme);
|
|
|
|
classList.add(newTheme);
|
|
|
|
localStorage.theme = newTheme;
|
|
|
|
themeSwitcher.innerHTML = text;
|
2021-08-04 03:49:55 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-18 10:34:01 +02:00
|
|
|
});
|