dark-mode-switch
dark-mode-switch copied to clipboard
Detect if user has prefers-dark-mode setting on
Requirements:
- dark-mode-switch should detect the users system preference and use that unless they have already made a change to the switch (which is saved in local storage). So if someone has already set the dark mode switch on, but they have a light-mode set on their OS or browser preference it would prioritise the dark-mode-switch setting
- I think this 'Detect if user has prefers-dark-mode setting on' feature should be enabled as standard in a v2 of this script, but open to suggestions if it should be an option.
I think this is something browsers will adopt sooner than later: See this stackoverflow answer.
In a cursory search, to check this via JavaScript you may follow this website's advice on a reactive JavaScript approach.
would be cool if we add a line of code to auto switch dark mode depending on time of the day. IF user local time passed sunset enable dark mode, else Light Mode.
I'd love to help out with this, if no one else is already working on it
Hi @filipe-gomes - yes, go for it! I updated my original post with a couple of thoughts on the requirements.
Hi @filipe-gomes - yes, go for it! I updated my original post with a couple of thoughts on the requirements.
Thanks! I'm working on a project where I just implemented that. I will start looking into implementing this with the switch tonight after work.
Hi @coliff -- looks like @popoway found a pretty easy solution to this ^^. Is that something you/we can add to the main source here?
I would like to work on it.
Is anyone already working on that? We may, as we have a downstream issue at https://github.com/coliff/dark-mode-switch/issues/2 implement this.