This repository has been archived on 2022-10-04. You can view files and clone it, but cannot push or open issues or pull requests.
2020-02-29 22:48:09 +00:00
|
|
|
window.addEventListener('load', () => {
|
|
|
|
// On page load, change the theme to light if they have that selected.
|
|
|
|
// Dark is selected by default.
|
|
|
|
const themeToggleButton = document.querySelector('button#theme-toggle');
|
|
|
|
if (window.localStorage.getItem('theme') === 'light-theme') {
|
|
|
|
document.body.setAttribute('id', 'light-theme');
|
|
|
|
themeToggleButton.classList.add('light');
|
|
|
|
}
|
|
|
|
|
|
|
|
// When the theme button is clicked, switch the theme to the other one.
|
2020-06-29 22:26:01 +00:00
|
|
|
themeToggleButton.addEventListener('click', (event) => {
|
2020-02-29 22:48:09 +00:00
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if (document.body.getAttribute('id') === 'dark-theme') {
|
|
|
|
document.body.setAttribute('id', 'light-theme');
|
|
|
|
themeToggleButton.classList.add('light');
|
|
|
|
} else {
|
|
|
|
document.body.setAttribute('id', 'dark-theme');
|
|
|
|
themeToggleButton.classList.remove('light');
|
|
|
|
}
|
|
|
|
|
|
|
|
window.localStorage.setItem('theme', document.body.getAttribute('id'));
|
|
|
|
});
|
|
|
|
});
|