最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to check if Dark Mode is enabled in Chrome extension - Stack Overflow

programmeradmin0浏览0评论

I would like to check if chrome is currently in dark mode to theme my extension accordingly.

I've already checked the chrome api but did not find any suitable option. Maybe there is some trick to find out the status. JavaScript or CSS should be fine.

I would like to check if chrome is currently in dark mode to theme my extension accordingly.

I've already checked the chrome api but did not find any suitable option. Maybe there is some trick to find out the status. JavaScript or CSS should be fine.

Share Improve this question asked May 13, 2019 at 9:29 Timo GrawTimo Graw 531 silver badge4 bronze badges 4
  • 1 medium.freecodecamp/… – A.A. Commented May 13, 2019 at 9:33
  • 1 Simply add @media (prefers-color-scheme: dark) { /* your dark theme here */ } – woxxom Commented May 13, 2019 at 10:15
  • Chrome 76 caniuse./prefers-color-scheme – Josh Lee Commented May 13, 2019 at 12:07
  • see also Toggle Chrome Extension Icon based on light or dark mode browser? – milahu Commented Dec 28, 2022 at 11:00
Add a ment  | 

1 Answer 1

Reset to default 10

In CSS (possible values are: light, dark, no-preference css docs) works with all modern browsers:

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

Follow up with JS (all modern browsers support this):

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

Bonus:

In electron:

const { systemPreferences } = require('electron')
console.log(systemPreferences.isDarkMode())
发布评论

评论列表(0)

  1. 暂无评论