Skip to content

Fix dark mode detection for system theme for highlight unfolded comments #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cherryblossom000
Copy link

@cherryblossom000 cherryblossom000 commented Jun 16, 2021

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 cherryblossom000 force-pushed the higlight-unfolded-comments-dark-mode-fix branch 2 times, most recently from 75ce95b to 3f37cd6 Compare June 18, 2021 09:17
@cherryblossom000 cherryblossom000 force-pushed the higlight-unfolded-comments-dark-mode-fix branch from 3f37cd6 to b4a907c Compare June 18, 2021 09:20
@cherryblossom000 cherryblossom000 changed the title Fix dark mode detection for highlight unfolded comments Fix dark mode detection for system theme for highlight unfolded comments Jun 18, 2021
@leonheess
Copy link

leonheess commented Nov 18, 2021

Can this please be merged? @CertainPerformance

@cherryblossom000
Copy link
Author

cherryblossom000 commented Nov 19, 2021

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] StackHighlightUnfoldedComments not working in dark mode
2 participants