Skip to content

Commit

Permalink
Added system mode detection for dark and light themes (Rakesh9100#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepeshahlawat authored Jan 22, 2025
1 parent 66c8a87 commit 75a11f8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,23 @@ document.addEventListener('DOMContentLoaded', function () {
});
});

// Dark mode toggle
// Dark mode toggle based on preference
function applyDarkModePreference() {
const darkModeStatus = localStorage.getItem('darkMode');
if (darkModeStatus === 'enabled') {
document.body.classList.add('dark-mode');
} else {
document.body.classList.remove('dark-mode');
}
}

// Immediately apply the stored dark mode preference
applyDarkModePreference();

// Toggle dark mode and save the preference
document.getElementById('dark-mode-toggle').addEventListener('click', () => {
document.body.classList.toggle('dark-mode');
const isDarkMode = document.body.classList.toggle('dark-mode');
localStorage.setItem('darkMode', isDarkMode ? 'enabled' : 'disabled');
});

// Mobile menu functionality
Expand Down

0 comments on commit 75a11f8

Please sign in to comment.