Skip to content

Commit 8c5a0d9

Browse files
LightLight
authored andcommitted
fix: 修复首次点击夜间模式切换按钮可能不生效的问题
1 parent 3f678c0 commit 8c5a0d9

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/footer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ function show_date_time() {
132132
const modeSwitch = document.querySelector('.my_mode_switch');
133133
modeSwitch && modeSwitch.addEventListener('click', e => {
134134
e.stopPropagation();
135-
if (cookie.get('night') === '0') {
136-
document.body.classList.add('night');
137-
cookie.set('night', '1');
138-
console.log('开启夜间模式');
139-
} else {
135+
if (cookie.get('night') === '1') {
140136
document.body.classList.remove('night');
141137
cookie.set('night', '0');
142138
console.log('关闭夜间模式');
139+
} else {
140+
document.body.classList.add('night');
141+
cookie.set('night', '1');
142+
console.log('开启夜间模式');
143143
}
144144
});
145145
<?php endif; ?>

src/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<!DOCTYPE html>
1818
<html lang="zh">
1919
<?php $this->need('header.php'); ?>
20-
<body class="page-body <?php echo $_COOKIE['night'] == '1' ? 'night' : ''; ?>">
20+
<body class="page-body <?php echo isset($_COOKIE['night']) && $_COOKIE['night'] == '1' ? 'night' : ''; ?>">
2121
<!-- skin-white -->
2222
<div class="page-container">
2323
<?php $this->need('sidebar.php'); ?>

0 commit comments

Comments
 (0)