sandoche / Darkmode.js

🌓 Add a dark-mode / night-mode to your website in a few seconds
https://darkmodejs.learn.uno
MIT License
2.71k stars 175 forks source link

Saving Mode #66

Closed markwsac closed 3 years ago

markwsac commented 3 years ago

When I disconnect my app and connect it again darkmode shows the last set mode. How can i disable it so that darkmode is inactive while app initiates?

**<input id="darktoggle" type="checkbox"/>**  

          const options = {autoMatchOsTheme: false}
          const darkmode =  new Darkmode(options);

          $('#darktoggle').click(function(){
              darkmode.toggle();
          });

           if (darkmode.isActivated()) {
              document.getElementById('darktoggle').checked = true;
            }
          else {
                document.getElementById('darktoggle').checked = false;
          }
sandoche commented 3 years ago

You need to play with this options:

const options = {
  saveInCookies: false, // default: true,
  autoMatchOsTheme: true // default: true
}

saveInCookies is the one that remember the darkmode last choice. autoMatchOsTheme will trigger automatically the OS theme!