Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
22 lines (18 sloc)
525 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const themeMap = { | |
dark: "light", | |
light: "solar", | |
solar: "dark" | |
}; | |
const theme = localStorage.getItem('theme') | |
|| (tmp = Object.keys(themeMap)[0], | |
localStorage.setItem('theme', tmp), | |
tmp); | |
const bodyClass = document.body.classList; | |
bodyClass.add(theme); | |
function toggleTheme() { | |
const current = localStorage.getItem('theme'); | |
const next = themeMap[current]; | |
bodyClass.replace(current, next); | |
localStorage.setItem('theme', next); | |
} | |
document.getElementById('themeButton').onclick = toggleTheme; |