From 9d3af603dfd135807919e0961d7926682fbc3729 Mon Sep 17 00:00:00 2001 From: Sayyad Aslam Date: Sat, 8 Jun 2024 22:45:00 +0530 Subject: [PATCH] Resolved Dark mode issue --- assets/js/script.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/assets/js/script.js b/assets/js/script.js index 238469f452..1ab605cb4e 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -198,14 +198,27 @@ for (let i = 0; i < filterBtn.length; i++) { // Code for enabling Light-Dark THEME +function applyTheme() { + var slider = document.getElementById("themeToggle"); + var isDarkTheme = localStorage.getItem("isDarkTheme"); + if (isDarkTheme === "true") { + slider.checked = true; + enableDarkTheme(); + } else { + slider.checked = false; + disableDarkTheme(); + } +} function toggleTheme() { var slider = document.getElementById("themeToggle"); if (slider.checked) { - disableDarkTheme(); - } else { + localStorage.setItem("isDarkTheme", "true"); enableDarkTheme(); + } else { + localStorage.setItem("isDarkTheme", "false"); + disableDarkTheme(); } } @@ -245,6 +258,8 @@ function disableDarkTheme() { } } +document.addEventListener("DOMContentLoaded", applyTheme); + window.onscroll = function() {scrollFunction()}; function scrollFunction() {