ybbond

My site. The main domain
Log | Files | Refs | README | LICENSE | CC-LICENSE

darkToggler.js (984B)


      1 (function() {
      2   const toggler = document.getElementById("dark-toggler");
      3   const mainWrapper = document.getElementById("main-theme");
      4   const currentTheme = localStorage.getItem("theme");
      5 
      6   if (toggler && mainWrapper) {
      7     toggler.className = "header__menu__list__toggler";
      8     toggler.onclick = function() {
      9       if (mainWrapper.className === "theme-light") {
     10         mainWrapper.className = "theme-dark";
     11         localStorage.setItem("theme", "dark");
     12         toggler.innerText = "🌛";
     13       } else if (mainWrapper.className === "theme-dark") {
     14         mainWrapper.className = "theme-light";
     15         localStorage.setItem("theme", "light");
     16         toggler.innerText = "🌞";
     17       }
     18     };
     19   }
     20 
     21   if (currentTheme && currentTheme === "light") {
     22     mainWrapper.className = "theme-light";
     23     toggler.innerText = "🌞";
     24   }
     25 
     26   console.log("Nice! You have the privilege of toggling the dark mode :D");
     27   console.log("Just press the 🌞 or 🌛 logo on the top of page!");
     28 })()