2023-10-15 19:40:48 -04:00
|
|
|
// Saves themes in-between pages to LocalStorage.
|
|
|
|
const themeSwitcher = document.getElementById('theme-switcher');
|
2019-03-29 00:32:42 -04:00
|
|
|
|
2023-10-15 19:40:48 -04:00
|
|
|
const setTheme = e => localStorage.setItem('theme', e.target.checked ? 'dark' : 'light');
|
|
|
|
const checkTheme = () => themeSwitcher.checked = localStorage.getItem('theme') === 'dark';
|
2019-03-29 00:32:42 -04:00
|
|
|
|
|
|
|
// Ensures backward compatibility with IE old versions
|
2023-10-15 19:40:48 -04:00
|
|
|
if (document.addEventListener) {
|
|
|
|
themeSwitcher.addEventListener('click', setTheme);
|
|
|
|
} else if (document.attachEvent) {
|
|
|
|
themeSwitcher.attachEvent('onclick', setTheme);
|
2019-03-29 00:32:42 -04:00
|
|
|
}
|
|
|
|
|
2023-10-15 19:40:48 -04:00
|
|
|
checkTheme()
|