Skip to content

Instantly share code, notes, and snippets.

@mhanberg
Created February 13, 2019 01:25
Show Gist options
  • Save mhanberg/b7a72cf685a77ba4c11b30494754ea69 to your computer and use it in GitHub Desktop.
Save mhanberg/b7a72cf685a77ba4c11b30494754ea69 to your computer and use it in GitHub Desktop.
function toggleTheme() {
const theme = window.localStorage.getItem("theme");
if (theme === "light") {
setTheme("#262b2f", "white", "๐ŸŒ", "dark");
} else {
setTheme("white", "#262b2f", "๐ŸŒš", "light");
}
}
function setTheme(background, text, toggleText, theme) {
document.body.style.setProperty("--background-color", background);
document.body.style.setProperty("--text-color", text);
document.getElementById("theme-btn").innerText = toggleText;
window.localStorage.setItem("theme", theme);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment