Skip to content

Commit cfeceb7

Browse files
committed
feat: 默认黑色主题
1 parent 486a5cf commit cfeceb7

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

doc/css/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ section.cover blockquote>p>a:hover {
744744

745745
.sidebar,
746746
body {
747-
background-color: var(--background);
747+
background-color: var(--background, #091a28);
748748
transition: background-image .15s ease-in-out .15s
749749
}
750750

doc/index.html

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
<div id="app">加载中...</div>
126126

127127
<script>
128-
(function checkHash() {
128+
function checkHash() {
129129
const hash = window.location.hash
130130

131131
// 判断是否以 #/en/ 或 #/zh/ 开头
@@ -144,7 +144,18 @@
144144
const newUrl = window.location.origin + window.location.pathname + window.location.search + newHash
145145
window.location.replace(newUrl)
146146
}
147-
})()
147+
}
148+
149+
function checkTheme() {
150+
// 默认黑色主题
151+
let theme = window.localStorage.getItem('DARK_LIGHT_THEME')
152+
if (!theme) {
153+
window.localStorage.setItem('DARK_LIGHT_THEME', 'dark')
154+
}
155+
}
156+
157+
checkHash()
158+
checkTheme()
148159

149160
window.$docsify = {
150161
name: 'Listen-文档中心',
@@ -181,7 +192,7 @@
181192
// 解析完文档后
182193
hook.afterEach(function (html, next) {
183194
const styles = window.getComputedStyle(document.documentElement)
184-
const isDark = styles.getPropertyValue('color-scheme') === 'dark'
195+
const isDark = styles.getPropertyValue('color-scheme') === 'dark' || window.localStorage.getItem('DARK_LIGHT_THEME') === 'dark'
185196
if (isDark) {
186197
html = html.replaceAll('/img/light/', '/img/dark/')
187198
} else {

0 commit comments

Comments
 (0)