mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-06 07:26:45 +00:00
自动深色模式
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import lang from './lang'
|
import lang from './lang'
|
||||||
import { useContext, createContext, useState, useEffect } from 'react'
|
import { useContext, createContext, useState } from 'react'
|
||||||
import Router from 'next/router'
|
import Router from 'next/router'
|
||||||
import { initDarkMode } from './theme'
|
import { initDarkMode } from './theme'
|
||||||
const GlobalContext = createContext()
|
const GlobalContext = createContext()
|
||||||
|
|||||||
15
lib/theme.js
15
lib/theme.js
@@ -1,4 +1,5 @@
|
|||||||
import cookie from 'react-cookies'
|
import cookie from 'react-cookies'
|
||||||
|
import BLOG from '@/blog.config'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化主题
|
* 初始化主题
|
||||||
@@ -23,10 +24,16 @@ export const initDarkMode = (isDarkMode, updateDarkMode) => {
|
|||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
export function isPreferDark () {
|
export function isPreferDark () {
|
||||||
// 系统深色模式或时间是夜间时,强行置为夜间模式
|
if (BLOG.APPEARANCE === 'dark') {
|
||||||
const date = new Date()
|
return true
|
||||||
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
|
}
|
||||||
return prefersDarkMode || (date.getHours() >= 18 || date.getHours() < 6)
|
if (BLOG.APPEARANCE === 'auto') {
|
||||||
|
// 系统深色模式或时间是夜间时,强行置为夜间模式
|
||||||
|
const date = new Date()
|
||||||
|
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||||
|
return prefersDarkMode || (date.getHours() >= 18 || date.getHours() < 6)
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user