text light and dark at home page

This commit is contained in:
2025-01-13 16:47:26 +02:00
parent f34164002c
commit 256fe586ab
8 changed files with 90 additions and 45 deletions

View File

@@ -191,3 +191,29 @@ function formatStatsData(stats) {
readingTime();
getStats();
document.getElementById("year").innerHTML = new Date().getFullYear();
// Get the toggle switch
const toggleSwitch = document.getElementById('darkModeSwitch');
// Apply the saved theme on load
document.addEventListener('DOMContentLoaded', () => {
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
document.body.classList.add('dark-mode');
toggleSwitch.checked = true;
}
});
// Toggle dark mode
toggleSwitch.addEventListener('change', () => {
if (toggleSwitch.checked) {
document.body.classList.add('dark-mode');
localStorage.setItem('theme', 'dark');
} else {
document.body.classList.remove('dark-mode');
localStorage.setItem('theme', 'light');
}
});