Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Update appbar.ejs
Browse files Browse the repository at this point in the history
  • Loading branch information
Halyul authored May 21, 2020
1 parent a1690dd commit c6fa0b1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions layout/_partials/js/appbar.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
// true for dark mode, false for bright mode
if(modeFlag === "true"){
document.querySelector('body').classList.add('mdui-theme-layout-dark')
document.querySelector('meta[name="theme-color"]').setAttribute("content", "#212121")
return true
} else if(!window.matchMedia) {
return false;
} else if(window.matchMedia("(prefers-color-scheme: dark)").matches) {
document.querySelector('body').classList.add('mdui-theme-layout-dark')
document.querySelector('meta[name="theme-color"]').setAttribute("content", "#212121")
return true;
} else if(window.matchMedia("(prefers-color-scheme: light)").matches) {
document.querySelector('body').classList.remove('mdui-theme-layout-dark')
document.querySelector('meta[name="theme-color"]').setAttribute("content", "#fff")
return false;
} else {
return false;
Expand All @@ -40,11 +43,13 @@
if (!modeFlag) {
// default bright mode, switch to dark mode
document.querySelector('body').classList.add('mdui-theme-layout-dark');
document.querySelector('meta[name="theme-color"]').setAttribute("content", "#212121")
localStorage.setItem('darkMode', true);
modeFlag = true;
} else {
// dark mode, switch to bright mode
document.querySelector('body').classList.remove('mdui-theme-layout-dark');
document.querySelector('meta[name="theme-color"]').setAttribute("content", "#fff")
localStorage.setItem('darkMode', false);
modeFlag = false;
}
Expand Down

0 comments on commit c6fa0b1

Please sign in to comment.