Skip to content

Commit

Permalink
feat: Possibilité de changer le dark mode depuis la page des menus
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulBayfield committed Sep 16, 2024
1 parent 9e22450 commit 4ab7a04
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,34 @@ console.info(`[Better IUT RCC] Version : ${manifestData.version}`);
// Remplace le contenu de la page actuelle par le contenu HTML reçu
document.documentElement.innerHTML = html.innerHTML;

const darkModeButton = document.getElementById("darkMode");
if (darkModeButton) {
darkModeButton.addEventListener("click", async function () {
console.info("[Better IUT RCC] Changement de thème en cours...");

let theme = '&theme=light';
if (document.querySelector('body').classList.contains('dark-theme')) {
document.querySelector('body').classList.remove('dark-theme');
darkModeButton.innerHTML = '<i class="fas fa-adjust"></i> Dark Mode Off';
let theme = '&theme=light';
} else {
document.querySelector('body').classList.add('dark-theme');
darkModeButton.innerHTML = '<i class="fas fa-adjust"></i> Dark Mode On';
theme = '&theme=dark';
}

var restaurant = document.getElementById("restaurant").value;
var img = document.getElementById("image-menu");

img.src = "https://croustillant.bayfield.dev/api/intranet?restaurant=" + restaurant + theme;

browser.storage.local.set({ darkTheme: document.querySelector('body').classList.contains('dark-theme') });

console.info("[Better IUT RCC] Thème actuel : " + (document.querySelector('body').classList.contains('dark-theme') ? "clair" : "sombre"));
console.info("[Better IUT RCC] Changement de thème terminé !");
});
}

// Gestion du thème sombre
applyTheme();

Expand Down

0 comments on commit 4ab7a04

Please sign in to comment.