From 4ab7a04e21939ee33c26dd53207bc8b9b7ff501a Mon Sep 17 00:00:00 2001
From: PaulBayfield <137620008+PaulBayfield@users.noreply.github.com>
Date: Mon, 16 Sep 2024 11:31:09 +0200
Subject: [PATCH] =?UTF-8?q?feat:=20Possibilit=C3=A9=20de=20changer=20le=20?=
=?UTF-8?q?dark=20mode=20depuis=20la=20page=20des=20menus?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main.js | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/src/main.js b/src/main.js
index 0100dcc..a880543 100644
--- a/src/main.js
+++ b/src/main.js
@@ -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 = ' Dark Mode Off';
+ let theme = '&theme=light';
+ } else {
+ document.querySelector('body').classList.add('dark-theme');
+ darkModeButton.innerHTML = ' 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();