kiwix-js
kiwix-js copied to clipboard
Add DarkReader plugin as an optional dark theme
I have been experimenting (successfully) in KJSW with the open-source DarkReader plugin: https://github.com/darkreader/darkreader. It is a simple JavaScript dependency (single file). It would work only in ServiceWorker Mode. All that is needed is to inject the script into the HTML document, and it analyses the document and generates specific CSS for a dark theme. The advantage of this is that maintenance of it is crowd-sourced, and that there are various options that can be tweaked.
There is one potential disadvantage: to work without the screen flashing to white between each page load, it may be necessary to inject the script into the HTML before it is rendered by the browser, which means adding it at the point at which the HTML is received from the back end. It may be possible to avoid this by hiding the document until the script is added through DOM methods, and then allowing it to render. Either way, I think it can be injected in a way that would not interfere with #870 (i.e. using new libzim WASM).
I would propose including this alongside our exisitng Dark Theme options.