Skip to content

Commit

Permalink
fix: 错误的添加类方式
Browse files Browse the repository at this point in the history
  • Loading branch information
yanranxiaoxi committed Aug 31, 2024
1 parent 18c56c1 commit 262e49a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions assets/js/match-dark-mode.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const expiredTime = new Date()
expiredTime.setTime(new Date().getTime() + 372 * 24 * 60 * 60 * 1000)
if (matchMedia('(prefers-color-scheme: dark)').matches) {
document.getElementsByTagName('body').addClass('dark');
document.getElementsByTagName('body').removeClass('light');
document.getElementsByTagName('body')[0].classList.add('dark');
document.getElementsByTagName('body')[0].classList.remove('light');
document.cookie = 'latest-prefers-color-scheme=dark; expires=' + expiredTime.toUTCString();
} else if (matchMedia('(prefers-color-scheme: light)').matches) {
document.getElementsByTagName('body').addClass('light');
document.getElementsByTagName('body').removeClass('dark');
document.getElementsByTagName('body')[0].classList.add('light');
document.getElementsByTagName('body')[0].classList.remove('dark');
document.cookie = 'latest-prefers-color-scheme=light; expires=' + expiredTime.toUTCString();
}

0 comments on commit 262e49a

Please sign in to comment.