Coder Social home page Coder Social logo

Comments (5)

rugk avatar rugk commented on June 3, 2024

Oh, that sounds hard. πŸ€”

from website-dark-mode-switcher.

rugk avatar rugk commented on June 3, 2024

If anyone has an example website/snippet that would already help.

from website-dark-mode-switcher.

ybungalobill avatar ybungalobill commented on June 3, 2024
<picture>
	<source media="(prefers-color-scheme: dark)" type="image/svg+xml" srcset="dark.svg" />
	<source media="not all and (prefers-color-scheme: dark)" type="image/svg+xml" srcset="light.svg" />
	<img src="default.png" height="32" width="180" />
</picture>

from website-dark-mode-switcher.

rugk avatar rugk commented on June 3, 2024

Okay thanks, I briefly looked into this and I can only say it is more complicated.
I created this fiddle: https://jsfiddle.net/uef8gdcy/4/

As I parse the document.styleSheets, which is the core of this add-on, and yeah there is a media, where this is exposed:
grafik

AFAIK, the current behaviour is actually buggy. The <style> tag media queries are ignored and all evaluated by this add-on. It cannot/does not differentiate between the media types.

So I've tried document.styleSheets[3].media.deleteMedium("(prefers-color-scheme: dark)") and it works. So yeah, we could modify that apparently. However, we would need to save the state somewhere there, as we currently extract and inject CSS manually. However now we would need to remember the previous state in order to be able to restore it when the toggle is triggered. πŸ˜ƒ
So anyway, PRs are of course always appreciated.

That said, even this does not fix the image/picture element, which is yet another issue…

from website-dark-mode-switcher.

rugk avatar rugk commented on June 3, 2024

Hi, I have great news for you! According to my testing, the latest v2.0 release fixes this issue due to the way it now uses a completely new API to do "dark-mode-changing" "properly". For more information, please see the release notes. If the issue should not be fixed, please let me know.

from website-dark-mode-switcher.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.