[英]How to check if Dark Mode is enabled in Chrome extension
I would like to check if chrome is currently in dark mode to theme my extension accordingly.我想检查 chrome 当前是否处于暗模式以相应地为我的扩展设置主题。
I've already checked the chrome api but did not find any suitable option.我已经检查了 chrome api,但没有找到任何合适的选项。 Maybe there is some trick to find out the status.
也许有一些技巧可以找出状态。 JavaScript or CSS should be fine.
JavaScript 或 CSS 应该没问题。
In CSS (possible values are: light
, dark
, no-preference
css docs ) works with all modern browsers :在 CSS 中(可能的值是:
light
, dark
, no-preference
css docs )适用于所有现代浏览器:
@media (prefers-color-scheme: light) {
.themed {
background: white;
color: black;
}
}
Follow up with JS ( all modern browsers support this ):跟进 JS(所有现代浏览器都支持这个):
window.matchMedia('(prefers-color-scheme: dark)')
Bonus:奖金:
In electron:在电子中:
const { systemPreferences } = require('electron')
console.log(systemPreferences.isDarkMode())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.