parent
eee9b3d8dd
commit
5b0726539b
Before Width: | Height: | Size: 152 KiB After Width: | Height: | Size: 152 KiB |
After Width: | Height: | Size: 152 KiB |
After Width: | Height: | Size: 152 KiB |
After Width: | Height: | Size: 4.9 KiB |
@ -0,0 +1,41 @@
|
||||
// Quand le document est prêt
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const currentTheme = localStorage.getItem('theme') || 'dark'; // Par défaut, sombre
|
||||
const themeIcon = document.getElementById('theme-icon');
|
||||
const favicon = document.getElementById('favicon'); // Sélectionne la favicon
|
||||
|
||||
// Applique le bon thème au chargement de la page
|
||||
if (currentTheme === 'light') {
|
||||
document.body.classList.remove('dark-mode');
|
||||
document.body.classList.add('light-mode');
|
||||
themeIcon.src = '../images/light.svg'; // Affiche l'icône pour basculer vers le mode sombre
|
||||
favicon.href = '../images/iconeClaire.ico'; // Favicon pour le mode clair
|
||||
} else {
|
||||
document.body.classList.add('dark-mode');
|
||||
themeIcon.src = '../images/dark.svg'; // Affiche l'icône pour basculer vers le mode clair
|
||||
favicon.href = '../images/iconeSombre.ico'; // Favicon pour le mode sombre
|
||||
}
|
||||
});
|
||||
|
||||
// Fonction pour basculer entre les thèmes
|
||||
function toggleTheme() {
|
||||
const body = document.body;
|
||||
const themeIcon = document.getElementById('theme-icon');
|
||||
const favicon = document.getElementById('favicon'); // Sélectionne la favicon
|
||||
|
||||
if (body.classList.contains('dark-mode')) {
|
||||
// Si on est en mode sombre, on passe en mode clair
|
||||
body.classList.remove('dark-mode');
|
||||
body.classList.add('light-mode');
|
||||
themeIcon.src = '../images/light.svg'; // Change vers le logo sombre
|
||||
favicon.href = '../images/iconeClaire.ico'; // Favicon pour le mode clair
|
||||
localStorage.setItem('theme', 'light'); // Enregistre le thème clair dans localStorage
|
||||
} else {
|
||||
// Sinon, on repasse en mode sombre
|
||||
body.classList.remove('light-mode');
|
||||
body.classList.add('dark-mode');
|
||||
themeIcon.src = '../images/dark.svg'; // Change vers le logo clair
|
||||
favicon.href = '../images/iconeSombre.ico'; // Favicon pour le mode sombre
|
||||
localStorage.setItem('theme', 'dark'); // Enregistre le thème sombre dans localStorage
|
||||
}
|
||||
}
|
Loading…
Reference in new issue