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