如下图在网上搜了一圈发现了如下代码即可判断当前系统是否为夜间模式
1
window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
就这一行代码即可实现跟随系统开启夜间模式,让网站的逼格瞬间提升~