@@ -288,21 +288,51 @@ <h1>
288
288
</ script >
289
289
< script src ="https://cdn.gtranslate.net/widgets/latest/popup.js " defer > </ script >
290
290
</ li >
291
- <!-- <div class="theme-switch themeSwitch" id="theme-switch"></div> -->
292
-
293
291
< div id ="themeSwitch " class ="theme-switch ">
294
292
< input type ="checkbox " class ="checkbox " id ="checkbox ">
295
293
< label for ="checkbox " class ="checkbox-label ">
296
-
297
294
< img src ="./Assets/sun.png " class ="theme-btn ">
298
295
< img src ="./Assets/moon.png " class ="theme-btn ">
299
- <!-- <i class="fas fa-moon"></i>
300
- <i class="fas fa-sun"></i> -->
301
296
< span class ="ball "> </ span >
302
297
</ label >
303
298
</ div >
304
- </ ul >
305
- </ nav >
299
+
300
+ < script >
301
+ // Function to toggle the theme and update local storage
302
+ const toggleTheme = ( ) => {
303
+ const checkbox = document . getElementById ( "checkbox" ) ;
304
+ if ( checkbox . checked ) {
305
+ document . body . classList . add ( "dark-mode" ) ; // Update to match your CSS
306
+ localStorage . setItem ( "theme" , "dark" ) ; // Save theme to localStorage
307
+ } else {
308
+ document . body . classList . remove ( "dark-mode" ) ; // Update to match your CSS
309
+ localStorage . setItem ( "theme" , "light" ) ; // Save theme to localStorage
310
+ }
311
+ } ;
312
+
313
+ // Load the theme from local storage on page load
314
+ const loadTheme = ( ) => {
315
+ const theme = localStorage . getItem ( "theme" ) ;
316
+ const checkbox = document . getElementById ( "checkbox" ) ;
317
+
318
+ // Check the stored theme and apply it
319
+ if ( theme === "dark" ) {
320
+ checkbox . checked = true ; // Set checkbox state
321
+ document . body . classList . add ( "dark-mode" ) ; // Apply dark theme
322
+ } else {
323
+ checkbox . checked = false ; // Set checkbox state
324
+ document . body . classList . remove ( "dark-mode" ) ; // Apply light theme
325
+ }
326
+ } ;
327
+
328
+ // Event listener for the checkbox
329
+ document . getElementById ( "checkbox" ) . addEventListener ( "change" , toggleTheme ) ;
330
+
331
+ // Call the function to load the theme when the page loads
332
+ window . onload = loadTheme ;
333
+ </ script >
334
+ </ ul >
335
+ </ nav >
306
336
307
337
</ header >
308
338
0 commit comments