Skip to content

Commit

Permalink
fix: dark mode persists in LocalStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishenderson07 committed Oct 3, 2023
1 parent 8dc75ad commit 3917b55
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,33 @@ const errMsg = document.querySelector('.err-msg')

const countryCode = document.querySelector('select')



// dark mode
const toggleButton = document.getElementById('toggleMode');
const body = document.body;
const colorMode = localStorage.getItem('color-mode') || 'light';

if(localStorage.getItem('color-mode') === 'dark'){
body.classList.add('dark-mode');
}

function toggleColorMode(){
let colorMode = localStorage.getItem('color-mode')

if (colorMode !== 'dark' || colorMode === null) {
body.classList.add('dark-mode');
localStorage.setItem('color-mode', 'dark');
} else {
body.classList.remove('dark-mode');
localStorage.setItem('color-mode', 'light');
}
}


toggleButton.addEventListener('click', toggleColorMode);


toggleButton.addEventListener('click', () => {
body.classList.toggle('dark-mode');
});

// Magic (text on phone)
let numPhone = document.getElementById('magic-num')
Expand Down

0 comments on commit 3917b55

Please sign in to comment.