Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. function checkTime() {
  2. var timeNow = new Date().getHours();
  3. const night = timeNow >= 16 || timeNow <= 7;
  4. return [timeNow, night];
  5. }
  6. function autoToggleNightMode() {
  7. const bodyClass = document.body.classList;
  8. var myinput = document.getElementsByClassName("switch")[0].getElementsByTagName("input")[0];
  9. var currentTime = checkTime()[0];
  10. var nightHours = checkTime()[1];
  11. if (document.cookie.indexOf("linx_dark") !== -1) {
  12. clearInterval(checkNightMode);
  13. return false;
  14. }
  15. if (nightHours === true) {
  16. myinput.setAttribute("checked", "checked");
  17. bodyClass.contains("dark-mode") === false ? bodyClass.add("dark-mode") : null;
  18. console.log("I've defined hour " + currentTime + " of the day as part of the 'night', so I'm automatically toggling night mode on for you!");
  19. } else {
  20. myinput.hasAttribute("checked") ? myinput.removeAttribute("checked") : null;
  21. bodyClass.contains("dark-mode") === true ? bodyClass.remove("dark-mode") : null;
  22. console.log("It's not night time anymore!!");
  23. }
  24. }
  25. autoToggleNightMode();
  26. var checkNightMode = setInterval(autoToggleNightMode, 30000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement