Files
quality_recticel/py_app/app/static/script.js
2025-04-16 16:44:21 +03:00

34 lines
1.1 KiB
JavaScript

document.addEventListener('DOMContentLoaded', () => {
const themeToggle = document.getElementById('theme-toggle');
const body = document.body;
// Check for saved theme in localStorage
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
body.className = savedTheme;
updateButtonText();
}
// Toggle theme on button click
if (themeToggle) {
themeToggle.addEventListener('click', () => {
if (body.classList.contains('light-mode')) {
body.className = 'dark-mode';
localStorage.setItem('theme', 'dark-mode');
} else {
body.className = 'light-mode';
localStorage.setItem('theme', 'light-mode');
}
updateButtonText();
});
}
// Function to update the button text
function updateButtonText() {
if (body.classList.contains('light-mode')) {
themeToggle.textContent = 'Change to dark theme';
} else {
themeToggle.textContent = 'Change to light theme';
}
}
});