Skip to content

Commit

Permalink
added darkmode persistance; improved code quality (#339)
Browse files Browse the repository at this point in the history
* added darkmode persistance; improved code quality

* fixed strong type checking
  • Loading branch information
vivsh1999 authored Oct 16, 2022
1 parent 5db402d commit 8a3b7fc
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,37 @@ toggle1.addEventListener("click", modeSwitch);

// Darkmode/Lightmode + Making songs play when clicked

let isLight = true;
let isLight = localStorage.getItem("darkmode")==='false';

const updateMode = () => {
isLight
? (slider.style.backgroundImage = "url('./images/light.png')")
: (slider.style.backgroundImage = "url('./images/dark.png')");

isLight
? (toggle1.style.backgroundImage = "url('./images/light.png')")
: (toggle1.style.backgroundImage = "url('./images/dark.png')");

isLight
? (canvasBody.style.backgroundColor = "#fdd7d1")
: (canvasBody.style.backgroundColor = "#dadada");

isLight
? (canvasHead.style.backgroundColor = "#fdd7d1")
: (canvasHead.style.backgroundColor = "#dadada");

isLight
? (navB.style.backgroundColor = "#fdd7d1c4")
: (navB.style.backgroundColor = "#e1e1e1c4");

const rootElement = document.body;
rootElement.classList.toggle("darkMode");
if (isLight) {
slider.style.backgroundImage = "url('./images/light.png')";
toggle1.style.backgroundImage = "url('./images/light.png')"
canvasBody.style.backgroundColor = "#fdd7d1";
canvasHead.style.backgroundColor = "#fdd7d1";
navB.style.backgroundColor = "#fdd7d1c4";
rootElement.classList.remove("darkMode");
} else {
slider.style.backgroundImage = "url('./images/dark.png')";
toggle1.style.backgroundImage = "url('./images/dark.png')";
canvasBody.style.backgroundColor = "#dadada";
canvasHead.style.backgroundColor = "#dadada";
navB.style.backgroundColor = "#e1e1e1c4";
rootElement.classList.add("darkMode");
}
};

function modeSwitch() {
isLight = !isLight;
updateMode();
localStorage.setItem("darkmode",!isLight);
}
// This function will execute on initial load of page
window.onload = function () {
updateMode();
}

embed.style = "display:none";
let userHasClickedASong = false;

Expand Down

0 comments on commit 8a3b7fc

Please sign in to comment.