From 00021c2a7045dceb4268d60862f4422c7ce31f6a Mon Sep 17 00:00:00 2001 From: Anurag Bansal Date: Tue, 8 Oct 2024 19:14:09 +0530 Subject: [PATCH] toggle theme fixed --- script.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/script.js b/script.js index abcf0373..9c4ffe71 100644 --- a/script.js +++ b/script.js @@ -367,18 +367,31 @@ document.addEventListener('DOMContentLoaded', function() { moonIcon.className = 'moon-icon'; moonIcon.innerHTML = '🌙'; + const currentTheme = localStorage.getItem('theme'); + + if (currentTheme === 'dark') { + document.body.classList.add('dark-mode'); + modeToggle.replaceChild(moonIcon, sunIcon); + } else { + document.body.classList.add('light-mode'); + sunIcon.classList.add('glow'); + } + modeToggle.addEventListener('click', function() { document.body.classList.toggle('dark-mode'); document.body.classList.toggle('light-mode'); if (document.body.classList.contains('dark-mode')) { modeToggle.replaceChild(moonIcon, sunIcon); + localStorage.setItem('theme', 'dark'); } else { modeToggle.replaceChild(sunIcon, moonIcon); sunIcon.classList.add('glow'); + localStorage.setItem('theme', 'light'); } }); }); + // discount pop_up document.addEventListener('DOMContentLoaded', function() { // Show the popup after a slight delay