Skip to content

Commit

Permalink
Merge pull request #299 from anuragbansall/toggleTheme
Browse files Browse the repository at this point in the history
Toggle Theme Fixed
  • Loading branch information
samarth-6 authored Oct 8, 2024
2 parents 95b7b28 + 00021c2 commit 0041c44
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,18 +367,31 @@ document.addEventListener('DOMContentLoaded', function() {
moonIcon.className = 'moon-icon';
moonIcon.innerHTML = '🌙';

const currentTheme = localStorage.getItem('theme');

if (currentTheme === 'dark') {
document.body.classList.add('dark-mode');
modeToggle.replaceChild(moonIcon, sunIcon);
} else {
document.body.classList.add('light-mode');
sunIcon.classList.add('glow');
}

modeToggle.addEventListener('click', function() {
document.body.classList.toggle('dark-mode');
document.body.classList.toggle('light-mode');

if (document.body.classList.contains('dark-mode')) {
modeToggle.replaceChild(moonIcon, sunIcon);
localStorage.setItem('theme', 'dark');
} else {
modeToggle.replaceChild(sunIcon, moonIcon);
sunIcon.classList.add('glow');
localStorage.setItem('theme', 'light');
}
});
});

// discount pop_up
document.addEventListener('DOMContentLoaded', function() {
// Show the popup after a slight delay
Expand Down

0 comments on commit 0041c44

Please sign in to comment.