OpenGPT / client /js /theme-toggler.js
AchyuthGamer's picture
Duplicate from AchyuthGamer/Neonaa
0c4cce1
raw
history blame contribute delete
673 Bytes
var switch_theme_toggler = document.getElementById("theme-toggler");
switch_theme_toggler.addEventListener("change", toggleTheme);
function setTheme(themeName) {
localStorage.setItem("theme", themeName);
document.documentElement.className = themeName;
}
function toggleTheme() {
var currentTheme = localStorage.getItem("theme");
var newTheme = currentTheme === "theme-dark" ? "theme-light" : "theme-dark";
setTheme(newTheme);
switch_theme_toggler.checked = newTheme === "theme-dark";
}
(function () {
var currentTheme = localStorage.getItem("theme") || "theme-dark";
setTheme(currentTheme);
switch_theme_toggler.checked = currentTheme === "theme-dark";
})();