如何检查Chrome扩展程序中是否启用了暗模式

时间:2019-05-13 09:29:38

标签: javascript google-chrome google-chrome-extension

我想检查chrome当前是否处于暗模式,以对扩展程序进行相应的主题设置。

我已经检查了chrome API,但是找不到任何合适的选项。也许有一些技巧可以找出状态。 JavaScript或CSS应该没问题。

1 个答案:

答案 0 :(得分:1)

在CSS中(代替浅色可能是浅色,深色,无偏好css docsworks with all modern browsers

@media (prefers-color-scheme: light) {  
  .themed {  
     background: white;    
     color: black;  
  }
}

关注JS(all modern browsers support this):

window.matchMedia('(prefers-color-scheme: dark)')

enter image description here

奖金:

在电子中:

const { systemPreferences } = require('electron')
console.log(systemPreferences.isDarkMode())
相关问题