Stack-Exchange-Userscripts icon indicating copy to clipboard operation
Stack-Exchange-Userscripts copied to clipboard

Fix dark mode detection for system theme for highlight unfolded comments

Open cherryblossom000 opened this issue 3 years ago • 2 comments

When the dark mode is set to ‘System setting’, the theme-dark class isn't present and instead theme-system is on the body element.

Screenshot of HTML source of StackOverflow page, showing that the theme-dark class is not present on the body element. The body instead has a theme-system class which is referred to in the styles tab of the Chrome DevTools as @media (prefers-color-scheme: dark) body.theme-system.

This PR uses window.matchMedia if the body class is theme-system to detect if the prefers-color-scheme is dark.

Fixes #22

cherryblossom000 avatar Jun 16 '21 10:06 cherryblossom000

Can this please be merged? @CertainPerformance

leonheess avatar Nov 18 '21 17:11 leonheess

A workaround for now is to edit the userscript installed to include this patch (so you don't have to wait for this PR to be merged to use the fix).

cherryblossom000 avatar Nov 19 '21 05:11 cherryblossom000