update dark light mode

This commit is contained in:
2025-05-22 12:05:08 +03:00
parent ecfae1fa72
commit 417f1d0004
16 changed files with 238 additions and 38 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -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');
}
});