From 2ba0c005b93e667cc940530f550490cc2499bf0f Mon Sep 17 00:00:00 2001 From: nanxiaobei Date: Mon, 24 Oct 2022 21:31:58 +0800 Subject: [PATCH] refine theme logic --- layouts/partials/header.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 32c5638..d7845b2 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -37,8 +37,12 @@ // init const darkScheme = window.matchMedia('(prefers-color-scheme: dark)'); - const darkVal = localStorage.getItem('dark'); - setDark(darkVal ? darkVal === 'true' : darkScheme.matches); + if (htmlClass.contains('dark')) { + setDark(true); + } else { + const darkVal = localStorage.getItem('dark'); + setDark(darkVal ? darkVal === 'true' : darkScheme.matches); + } // listen system darkScheme.addEventListener('change', (event) => {