Skip to content

Add fallback for dark theme when localStorage isn't available #613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions examples/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(()=> {
Expand Down Expand Up @@ -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';
Expand All @@ -80,6 +80,7 @@

}else {
localStorage.setItem('currentToggle', 'night');
toggle = 'night';
body.style.backgroundColor = '#111111';
body.style.filter = 'invert(1)';
body.style.transitionProperty = 'filter';
Expand Down Expand Up @@ -131,4 +132,4 @@
$('.past').click((e) => buttonClickCallbackNightTheme(e));
$('.sort-options').click((e) => buttonClickCallbackNightTheme(e));

})
})