rugk / website-dark-mode-switcher

This is a (Firefox) add-on (WebExtension) that lets you invert the website's color scheme by inverting/changing the prefers-color-scheme media feature of CSS.
https://addons.mozilla.org/firefox/addon/dark-mode-website-switcher/?src=external-github-top
Other
58 stars 4 forks source link

Support setting light/dark mode on a per site/URL basis. #55

Closed vamega closed 1 year ago

vamega commented 1 year ago

Background

My system preference is set to use dark mode. I browse some websites where their dark mode theme makes the content barely legible. I use the extension to switch those website to use light mode (the websites in question use media queries, so forcing light mode works).

However this addon currently switches this preference across all sites in my browser.

Proposed solution

Allow associating this preference on a per-site basis.

Alternatives

Continue to toggle this on a per site basis.

Additional context

I'm unsure if the overrideContentColorScheme API allows changes like this to be isolated to a website. A quick scan of the code made me aware that this was the API that was being used to change the result of the media query prefers-color-scheme.

I was originally hoping to do this via Stylus, since it has the ability to set styles on a per site/per url basis, but couldn't find a way to change the result of the media query. This addon lets me change the result of the media-query, but applies that globally.

rugk commented 1 year ago

Thanks for your elaborate request. Yeah as you correctly noticed your feature request is hard to implement unfortunately. Actually this is a duplicate of https://github.com/rugk/website-dark-mode-switcher/issues/12, there it is also explained that the API is global, and AFAIK this has not changed until now, so there is nothing I can do.

What you could do or also work upon is using the old v1.3 version, which does what you basically wanted to do with Stylus. However, overriding that media query is way harder than you may think (feel free to look through the code and PRs by contributors) and ends up being quite unreliable, so for now I prefer to stick and use the Firefox API. More information about that history in the latest release notes for v2.0.

rugk commented 1 year ago

Duplicate of #12

vamega commented 1 year ago

Thanks so much for such a detailed response!