Ajouter js/theme.js

This commit is contained in:
2026-04-13 11:57:00 +00:00
parent ce9fdbe19f
commit cb8f36e188

22
js/theme.js Normal file
View File

@@ -0,0 +1,22 @@
function toggleTheme() {
const body = document.body;
const btn = document.getElementById('toggle-theme');
body.classList.toggle('light-mode');
if (body.classList.contains('light-mode')) {
btn.textContent = '🌙';
localStorage.setItem('theme', 'light');
} else {
btn.textContent = '☀️';
localStorage.setItem('theme', 'dark');
}
}
(function() {
const theme = localStorage.getItem('theme');
const btn = document.getElementById('toggle-theme');
if (theme === 'light') {
document.body.classList.add('light-mode');
if (btn) btn.textContent = '🌙';
}
})();