Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233// Get the theme toggle inputconst currentTheme = localStorage.getItem("theme"); // If the current local storage item can be found
if ( window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches && !localStorage.getItem("theme")) { localStorage.setItem("theme", "dark");}
// Function that will switch the theme based on the if the theme toggle is checked or notfunction switchTheme() { if (document.documentElement.getAttribute("data-theme") === "dark") { document.documentElement.setAttribute("data-theme", "light"); document.querySelector(".juttu-comments")?.setAttribute("data-juttu-theme", "light"); // Set the user's theme preference to dark localStorage.setItem("theme", "light"); } else { document.documentElement.setAttribute("data-theme", "dark"); document.querySelector(".juttu-comments")?.setAttribute("data-juttu-theme", "dark"); // Set the user's theme preference to light localStorage.setItem("theme", "dark"); }}
// Get the current theme from local storageif (currentTheme) { // Set the body data-theme attribute to match the local storage item document.documentElement.setAttribute("data-theme", currentTheme); document.querySelector(".juttu-comments")?.setAttribute("data-juttu-theme", currentTheme);}