update dark light mode
This commit is contained in:
		@@ -191,3 +191,34 @@ function formatStatsData(stats) {
 | 
			
		||||
readingTime();
 | 
			
		||||
getStats();
 | 
			
		||||
document.getElementById("year").innerHTML = new Date().getFullYear();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Get elements
 | 
			
		||||
const toggleSwitch = document.getElementById('lightModeSwitch');
 | 
			
		||||
const body = document.body;
 | 
			
		||||
 | 
			
		||||
// Apply saved theme on load
 | 
			
		||||
document.addEventListener('DOMContentLoaded', () => {
 | 
			
		||||
    const savedTheme = localStorage.getItem('theme') || 'light'; // Default is light mode
 | 
			
		||||
 | 
			
		||||
    if (savedTheme === 'light') {
 | 
			
		||||
        body.classList.add('light-mode');
 | 
			
		||||
        toggleSwitch.checked = true;
 | 
			
		||||
    } else {
 | 
			
		||||
        body.classList.remove('light-mode');
 | 
			
		||||
        toggleSwitch.checked = false;
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// Toggle between light and dark mode
 | 
			
		||||
toggleSwitch.addEventListener('change', () => {
 | 
			
		||||
    if (toggleSwitch.checked) {
 | 
			
		||||
        body.classList.add('light-mode');
 | 
			
		||||
        localStorage.setItem('theme', 'light');
 | 
			
		||||
    } else {
 | 
			
		||||
        body.classList.remove('light-mode');
 | 
			
		||||
        localStorage.setItem('theme', 'dark');
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user