From 2801ce21acb0167541050e63d468d647a1b921bb Mon Sep 17 00:00:00 2001 From: Mayank Kamboj Date: Mon, 24 Apr 2023 09:04:58 +0000 Subject: [PATCH 1/2] Dark theme without localStorage Make the dark theme work on browsers that have disabled cookies and localStorage access --- examples/themes.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/themes.js b/examples/themes.js index 7224ff24..5294581d 100644 --- a/examples/themes.js +++ b/examples/themes.js @@ -4,7 +4,7 @@ $(document).ready(() => { let body=document.querySelector('body'); let toggleButton=document.getElementById('myonoffswitch'); - let toggle = localStorage.getItem('currentToggle'); + let toggle = localStorage.getItem('currentToggle') || 'day'; // Sets images' theme accordingly when the page is loaded setTimeout(()=> { @@ -57,10 +57,10 @@ setTimeout(()=> { let images=document.querySelectorAll("img"); - let check=localStorage.getItem('currentToggle'); - if(check==="night") { + if(toggle==="night") { localStorage.setItem('currentToggle', 'day'); + toggle = 'day'; body.style.backgroundColor = '#f8f8fa'; body.style.filter = 'invert(0)'; body.style.transitionProperty = 'filter'; @@ -80,6 +80,8 @@ }else { localStorage.setItem('currentToggle', 'night'); + toggle = 'night'; + alert('niiight'); body.style.backgroundColor = '#111111'; body.style.filter = 'invert(1)'; body.style.transitionProperty = 'filter'; From 0ff28cb205bc0e2cdc7132283b3c94c6ad9abe3c Mon Sep 17 00:00:00 2001 From: Mayank Kamboj Date: Mon, 24 Apr 2023 02:20:38 -0700 Subject: [PATCH 2/2] Remove annoying alert message --- examples/themes.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/themes.js b/examples/themes.js index 5294581d..b2cb967c 100644 --- a/examples/themes.js +++ b/examples/themes.js @@ -81,7 +81,6 @@ }else { localStorage.setItem('currentToggle', 'night'); toggle = 'night'; - alert('niiight'); body.style.backgroundColor = '#111111'; body.style.filter = 'invert(1)'; body.style.transitionProperty = 'filter'; @@ -133,4 +132,4 @@ $('.past').click((e) => buttonClickCallbackNightTheme(e)); $('.sort-options').click((e) => buttonClickCallbackNightTheme(e)); -}) \ No newline at end of file +})