Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. window.addEventListener("DOMContentLoaded",(event)=>{
  2. if (typeof(Storage) !== "undefined") {
  3. light = localStorage.getItem("light");
  4. console.log("light="+localStorage.getItem("light"));
  5. darkMode();
  6. }
  7. else {
  8. localStorage.setItem("light",1);
  9. light = localStorage.getItem("light");
  10. console.log("light(else)="+localStorage.getItem("light"));
  11. darkMode();
  12. }
  13. document.getElementById("theButton").onclick =function() {darkMode()};
  14.  
  15. function darkMode() {
  16. if(light==1){
  17. document.getElementById("theButton").innerHTML = "Light mode";
  18. document.getElementById("header").style.borderColor = "white";
  19. document.body.style.backgroundColor = "#302B30";
  20. var a =document.getElementsByClassName("dark");
  21. for(var i=0; i<a.length; i++){
  22. a[i].style.color="white";
  23. a[i].onmouseout = function() {mouseOut()};
  24. }
  25.  
  26. localStorage.setItem("light",1);
  27. light = 0;
  28. console.log("light(lightmode=1)="+localStorage.getItem("light"));
  29. }
  30.  
  31. else if (light==0){
  32. document.getElementById("theButton").innerHTML = "Dark mode";
  33. document.getElementById("header").style.borderColor = "black";
  34. document.body.style.backgroundColor = "#F9F7F3";
  35. var a =document.getElementsByClassName("dark");
  36. for(var i=0; i<a.length; i++){
  37. a[i].style.color="black";
  38. a[i].onmouseout = function() {mouseOut()};
  39. }
  40. localStorage.setItem("light",0);
  41. light = 1;
  42. console.log("light(darkmode=0)="+localStorage.getItem("light"));
  43. }
  44.  
  45. function mouseOut() {
  46. document.getElementsByClassName("dark")
  47. if(light==1){
  48. for(var i=0; i<a.length; i++){
  49. a[i].style.color="black";
  50. }
  51. }
  52. if(light==0){
  53. for(var i=0; i<a.length; i++){
  54. a[i].style.color="white";
  55. }
  56. }
  57. }
  58. }
  59. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement