jothepro / doxygen-awesome-css

Custom CSS theme for doxygen html-documentation with lots of customization parameters.
https://jothepro.github.io/doxygen-awesome-css/
MIT License
981 stars 112 forks source link

Configure dark mode be the default on page load #48

Open jdillard opened 2 years ago

jdillard commented 2 years ago

As a fan of dark mode, I thought it would be nice to have a configuration option to set dark mode on initial page load. I started looking into how to implement it, but thought I would open a "feature request" just in case.

jothepro commented 2 years ago

Would you like to always enable dark mode, without providing the toggle button to the user? Or should dark be the default but the user should be allowed to disable it?

jdillard commented 2 years ago

The latter. I was thinking something like a config variable that added class="dark-mode" or class="light-mode" to the template and having the javascript check for the class, but I just realized that would require making another manual edit to the templates generated by Doxygen.

jothepro commented 2 years ago

The script in doxygen-awesome-darkmode-toggle.js reads a value from the local storage at page load to determine if it should enable dark mode. You could write a custom script that sets the key prefers-dark-mode-in-light-mode on the users first page visit, remembering if you did so in another key:

if(localStorage.getItem("kilroy-was-here") === null) {
  localStorage.setItem("kilroy-was-here", true)
  localStorage.setItem("prefers-dark-mode-in-light-mode", true)
}

Disclaimer: This is not a decent solution but more of a workaround for your requirement. It does also require the template to be edited (for adding the script). I've not tested if this works, but in my head it does :wink:)