Skip to content

Commit

Permalink
improve logic against exception cases
Browse files Browse the repository at this point in the history
Improve automatic dark mode setting logic.

+ avoid conflict errors, when other color was already set.

+ fix conflict errors, when dark was already set as the CSS class.
  • Loading branch information
Dorson authored Apr 18, 2020
1 parent dba7d73 commit 9da6761
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions JS-CSS-Color-Settings-Recall-on-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ document.addEventListener("DOMContentLoaded", AfterDark() , true ) ;

function AfterDark() {

var hour = new Date().getHours() ;
let hour = new Date().getHours() ;

if ( !localStorage.getItem( "ColorMode" ) && ( hour >= 20 || hour < 7 ) ) {
let ColorWasSet = localStorage.getItem( "ColorMode" ) ;

document.querySelector("html").classList.add( "dark" ) ;
let DarkWasSet = document.querySelector("html").classList.contains("dark") ;

if ( ( hour >= 20 || hour < 7 ) && !( ColorWasSet || DarkWasSet ) )
{
document.querySelector("html").classList.add( "dark" ) ;
}
}

0 comments on commit 9da6761

Please sign in to comment.