mirror of
https://github.com/zopiya/blog.git
synced 2025-11-03 20:16:47 +08:00
Add initial theme assets, layouts, and configuration for Hugo site
This commit is contained in:
28
themes/typo/static/js/theme-switch.js
Normal file
28
themes/typo/static/js/theme-switch.js
Normal file
@@ -0,0 +1,28 @@
|
||||
function isAuto() {
|
||||
return document.body.classList.contains("auto");
|
||||
}
|
||||
|
||||
function setTheme() {
|
||||
if (!isAuto()) {
|
||||
return
|
||||
}
|
||||
|
||||
document.body.classList.remove("auto");
|
||||
let cls = "light";
|
||||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
cls = "dark";
|
||||
}
|
||||
|
||||
document.body.classList.add(cls);
|
||||
}
|
||||
|
||||
function invertBody() {
|
||||
document.body.classList.toggle("dark");
|
||||
document.body.classList.toggle("light");
|
||||
}
|
||||
|
||||
if (isAuto()) {
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addListener(invertBody);
|
||||
}
|
||||
|
||||
setTheme();
|
||||
Reference in New Issue
Block a user