From a51d7273525d68a2221e0eabeae4986b2075358c Mon Sep 17 00:00:00 2001
From: AnkushjainAj <133674486+AnkushjainAj@users.noreply.github.com>
Date: Fri, 6 Oct 2023 20:35:43 +0530
Subject: [PATCH] Update index.html
Added theme button
---
index.html | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/index.html b/index.html
index 613d802..37aadeb 100644
--- a/index.html
+++ b/index.html
@@ -67,6 +67,7 @@
+
@@ -701,6 +702,34 @@
Technology, Information and Internet Kanpur
prevEl: '.swiper-button-prev',
}
});
+ const themeButton = document.getElementById('theme-button')
+const darkTheme = 'dark-theme'
+const iconTheme = 'ri-sun-line'
+
+// Previously selected topic (if user selected)
+const selectedTheme = localStorage.getItem('selected-theme')
+const selectedIcon = localStorage.getItem('selected-icon')
+
+// We obtain the current theme that the interface has by validating the dark-theme class
+const getCurrentTheme = () => document.body.classList.contains(darkTheme) ? 'dark' : 'light'
+const getCurrentIcon = () => themeButton.classList.contains(iconTheme) ? 'ri-moon-line' : 'ri-sun-line'
+
+// We validate if the user previously chose a topic
+if (selectedTheme) {
+ // If the validation is fulfilled, we ask what the issue was to know if we activated or deactivated the dark
+ document.body.classList[selectedTheme === 'dark' ? 'add' : 'remove'](darkTheme)
+ themeButton.classList[selectedIcon === 'ri-sun-line' ? 'add' : 'remove'](iconTheme)
+}
+
+// Activate / deactivate the theme manually with the button
+themeButton.addEventListener('click', () => {
+ // Add or remove the dark / icon theme
+ document.body.classList.toggle(darkTheme)
+ themeButton.classList.toggle(iconTheme)
+ // We save the theme and the current icon that the user chose
+ localStorage.setItem('selected-theme', getCurrentTheme())
+ localStorage.setItem('selected-icon', getCurrentIcon())
+})