pages/assets/js/theme.js
Maruan 4f9cdb131e
Minor fixes of the dark mode + automatic equation numbering (#160)
* Add an option for showing selected publications

* Improve publication styles

* Update README.md

* Clearfix

* Fix minor issues with dark mode

* Add automatic equation numbering (#158)

* Fix a typo
2020-12-27 00:24:25 -05:00

18 lines
454 B
JavaScript

// Has to be in the head tag, otherwise a flicker effect will occur.
let initTheme = (theme) => {
if (theme == null) {
const userPref = window.matchMedia;
if (userPref && userPref('(prefers-color-scheme: dark)').matches) {
theme = 'dark';
}
}
if (theme) {
document.documentElement.setAttribute('data-theme', theme)
}
localStorage.setItem("theme", theme);
}
initTheme(localStorage.getItem("theme"));