up script pour générer, ajout bouton themes

This commit is contained in:
Tykayn 2025-10-05 13:33:46 +02:00 committed by tykayn
parent 55e0f2a55c
commit 8abe2f6aad
5 changed files with 71 additions and 6 deletions

View file

@ -51,4 +51,37 @@ document.addEventListener('DOMContentLoaded', function () {
});
const themes_calsses = ['default', 'mastodon', 'another']
function makeThemesButton(){
// Crée un bouton pour changer de thème et l'ajoute au body
const boutonTheme = document.createElement('button');
boutonTheme.textContent = 'Changer de thème';
boutonTheme.id = 'theme-switcher';
document.body.appendChild(boutonTheme);
addEventListener('click', onClickThemeButton)
}
function onClickThemeButton(){
// Passer au thème suivant et appliquer la classe au body
// On suppose que themes_calsses est un tableau global
if (!window.currentThemeIndex && window.currentThemeIndex !== 0) {
// Initialiser l'index du thème courant en fonction de la classe actuelle du body
const currentClass = document.body.className;
window.currentThemeIndex = themes_calsses.indexOf(currentClass);
if (window.currentThemeIndex === -1) {
window.currentThemeIndex = 0;
}
}
// Passer au thème suivant
window.currentThemeIndex = (window.currentThemeIndex + 1) % themes_calsses.length;
// Appliquer la nouvelle classe au body
document.body.className = themes_calsses[window.currentThemeIndex];
}
});