Github-readme-stats: [Feature] Dark mode

Created on 16 Jul 2020  路  17Comments  路  Source: anuraghazra/github-readme-stats

It is a really useful feature, that we can change the colors of the stats, but I would appreciate some sort of auto dark mode With dark mode coming to GitHub, I think it will have to be done sooner or later.
Nat Friedman's hacker news profile

I have a couple of proposed solutions, but none of them seems perfect.

  1. If the auto theme is enabled, query a weather service such as The Open Weather API, to get the sunset time for the current timezone - I am not sure how to get the time zone though.

Example: client => Vercel <= Weather API

  1. It would be best if you could query the @prefers-color-scheme data of the browser, as no timezone or other preference data would be needed.

Query: https://github-readme-stats.vercel.app/api?username=anuraghazra&prefers=dark

  1. The hardest solution - we could contact GitHub directly, to perhaps provide a feature, to set alternative image sources according to the current theme.

Something like: GitHub README stats in markdown

design feature stale

All 17 comments

Thanks for requesting the feature @filiptronicek this sounds good, i'll see what i can do.
related to #66

  1. It would be best if you could query the @prefers-color-scheme data of the browser, as no timezone or other preference data would be needed.

It is nearly impossible to get the media query through an image element. And of course GitHub won't let you inject any <style> or <script> tag. It is just impossible.

An alternative is using <picture> and <source> tag:

   <picture>
      <source 
        srcset="settings-dark.png"
        media="(prefers-color-scheme: dark)"
      />
      <source
        srcset="settings-light.png"
        media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)"
      />
      <img src="settings-light.png" />
    </picture>

But I am not sure whether GitHub will allow us to use the <picture> & source tag.

@SukkaW true, but the issue is not about whether github supports style/script tags or not, we can put style tag on SVG and we are also doing CSS animations there, but the real problem is even if i put prefer-color-scheme media queries it would not change because the svg is rendered and uploaded to github's CDNs (although i did not tested if it works)

I have to do some testing to see if it works.

Let's see if this works: @SukkaW @anuraghazra

srcset="https://files.catbox.moe/shuph5.png"
media="(prefers-color-scheme: dark)"
/>
srcset="https://files.catbox.moe/zhopye.png"
media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)"
/>

@filiptronicek worked? Also even if it's works, kinda too much boilerplate and same as just swaping the colors (which we are doing right now)

So we can just render the white card on light mode and black on dark mode

Tried changing my preference on Chrome Beta, doesn't look like it would work :(

@anuraghazra @filiptronicek

image

image

No, it doesn't.

Hello folks, for dark mode it's working in local. Hope I will able to produce some update after deploy it and verify it in live mode.

@rjoydip that would be awesome! Super excited to see it in action

Hello folks, for dark mode it's working in local. Hope I will able to produce some update after deploy it and verify it in live mode.

Yes these stuff works locally but not in production because we are not serving directly from the server, github will reupload and serve from their CDNs.

Same issue I faced when detecting user agent #45

@filiptronicek @anuraghazra
Plese checkout below link of live deployment. It's working
https://github-readme-stats.rjoydip.vercel.app/api?username=rjoydip&show_icons=true

@rjoydip cool then, open the PR! :100:

Yes, but I will check with this in my README once before PR.

It's working in github.

PR #181

I'm still wondering why @filiptronicek's experiment failed, did you used the media queries inside the picture tag?

@anuraghazra I will bring up my own test again.

<picture>
      <source 
        srcset="https://via.placeholder.com/1000x618.png?text=Dark+Mode"
        media="(prefers-color-scheme: dark)"
      />
      <source
        srcset="https://via.placeholder.com/1000x618.png?text=Light+Mode"
        media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)"
      />
      <img src="https://via.placeholder.com/1000x618.png?text=Fallback+Mode" />
</picture>


srcset="https://via.placeholder.com/1000x618.png?text=Dark+Mode"
media="(prefers-color-scheme: dark)"
/>
srcset="https://via.placeholder.com/1000x618.png?text=Light+Mode"
media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)"
/>


Update

It appears that GitHub will transform the <picture> into simple <img>.

Yeah, Github does support SVG based CSS thats why we could do animations and stuff but not picture tags. so using media queries on picture tag wont work

<picture>
      <source 
        srcset="https://via.placeholder.com/1000x618.png?text=Dark+Mode"
        media="(prefers-color-scheme: dark)"
      />
      <source
        srcset="https://via.placeholder.com/1000x618.png?text=Light+Mode"
        media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)"
      />
      <img src="https://via.placeholder.com/1000x618.png?text=Fallback+Mode" />
</picture>

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cachecleanerjeet picture cachecleanerjeet  路  4Comments

kajweb picture kajweb  路  4Comments

HaaLeo picture HaaLeo  路  4Comments

IvanHornung picture IvanHornung  路  3Comments

nathanchu picture nathanchu  路  6Comments