2021-08-23 15:40:38 +02:00
|
|
|
const light = '{{ index .Site.Params.switch 1 }}',
|
|
|
|
dark = '{{ index .Site.Params.switch 0 }}';
|
2021-08-19 06:42:00 +02:00
|
|
|
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,
|
2021-08-29 17:55:45 +02:00
|
|
|
{ classList } = document.documentElement,
|
2021-08-19 06:42:00 +02:00
|
|
|
text = newTheme === LIGHT ? light : dark;
|
|
|
|
classList.remove(currentTheme);
|
|
|
|
classList.add(newTheme);
|
|
|
|
localStorage.theme = newTheme;
|
|
|
|
themeSwitcher.innerHTML = text;
|
|
|
|
});
|