summaryrefslogtreecommitdiffstats
path: root/assets/js
diff options
context:
space:
mode:
authordsrkafuu2021-06-09 10:43:38 +0800
committerdsrkafuu2021-06-09 10:43:38 +0800
commit7fede1b36755c85c084cb99c73d36c9cb0b1e2fb (patch)
treece3abd30c22dcd5df9f904262c94611dfdac52ea /assets/js
parent787b7865fba31fd56009a85f214f829b9d85cc04 (diff)
downloadhugo-theme-fuji-7fede1b36755c85c084cb99c73d36c9cb0b1e2fb.tar.gz
hugo-theme-fuji-7fede1b36755c85c084cb99c73d36c9cb0b1e2fb.tar.bz2
hugo-theme-fuji-7fede1b36755c85c084cb99c73d36c9cb0b1e2fb.zip
feat: default theme
Diffstat (limited to 'assets/js')
-rw-r--r--assets/js/fuji.js15
1 files changed, 7 insertions, 8 deletions
diff --git a/assets/js/fuji.js b/assets/js/fuji.js
index d2eab58..ed10d17 100644
--- a/assets/js/fuji.js
+++ b/assets/js/fuji.js
@@ -58,6 +58,7 @@ function updateUtterancesTheme(utterancesFrame) {
document.querySelector('.btn .btn-toggle-mode').addEventListener('click', () => {
let nowTheme = getNowTheme();
let domTheme = document.body.getAttribute('data-theme');
+ const needAuto = document.body.getAttribute('data-theme-auto') === 'true';
let systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
if (domTheme === 'auto') {
@@ -65,15 +66,13 @@ document.querySelector('.btn .btn-toggle-mode').addEventListener('click', () =>
document.body.setAttribute('data-theme', nowTheme === 'light' ? 'dark' : 'light');
localStorage.setItem('fuji_data-theme', nowTheme === 'light' ? 'dark' : 'light');
} else if (domTheme === 'light') {
- // if now in user mode and light mode
- document.body.setAttribute('data-theme', 'dark');
- // if the theme want to switch is system theme
- localStorage.setItem('fuji_data-theme', systemTheme === 'dark' ? 'auto' : 'dark');
+ const tar = systemTheme === 'dark' ? (needAuto ? 'auto' : 'dark') : 'dark';
+ document.body.setAttribute('data-theme', tar);
+ localStorage.setItem('fuji_data-theme', tar);
} else {
- // if now in user mode and dark mode
- document.body.setAttribute('data-theme', 'light');
- // if the theme want to switch is system theme
- localStorage.setItem('fuji_data-theme', systemTheme === 'light' ? 'auto' : 'light');
+ const tar = systemTheme === 'light' ? (needAuto ? 'auto' : 'light') : 'light';
+ document.body.setAttribute('data-theme', tar);
+ localStorage.setItem('fuji_data-theme', tar);
}
// switch comment area theme