Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Ref: #4167
- Loading branch information
1 parent
245a7a9
commit f9b2cd0
Showing
3 changed files
with
21 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
;(function () { | ||
const themeAttr = 'data-theme' | ||
const isInDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches | ||
|
||
if (getTheme() == null) { | ||
setTheme(isInDarkMode ? 'dark' : 'light') | ||
} else { | ||
setTheme(getTheme()) | ||
} | ||
|
||
function setTheme (theme) { | ||
document.querySelector('html').setAttribute(themeAttr, theme) | ||
window.localStorage.setItem('theme', theme) | ||
} | ||
|
||
function getTheme () { | ||
return window.localStorage.getItem('theme') | ||
} | ||
})() |