ThomazPom / Moz-Ext-UltimaDark

Web Extension that uses agressive technique to get dark mode everywhere
12 stars 3 forks source link

UltimaDark

This repository stores the source code for the UltimaDark Firefox extension The extension uses agressive techniques to get a dark mode everywhere on internet This is still highly experimental so it can also ruin your internet experience

UltimaDark stands out from other extensions in its category by altering colors even before the renderer (Gecko) processes them, which considerably improves performance. The UltimaDark code intercepts the page content at an early stage, right after it is fetched from the remote website. This preemptive editing prevents Gecko from displaying the default bright colors of the website before applying the dark theme, eliminating the jarring white flash during page loading.

During this initial edit, nothing has been parsed by Gecko yet — all values are still character strings. The challenge lies in identifying colors within these character strings and determining whether they will be used as background or foreground. This distinction is not an exact science, adding complexity to the process.

Once a color is detected, it undergoes the appropriate transformation, either darkening or brightening. After the transformation is complete, the original value is replaced in the character string, ready to be read by the renderer.

The adjustment of website colors, rather than implementing a dark theme, aims to preserve the authenticity of the website's intended design.

Let's focus specifically on the darkening transformation, as there are still refinements to be made in the brightening function.

² The darkening transformation begins by determining the lightness of the color. If it falls below a certain brightness threshold (B), it remains untouched, respecting the website's intended design.

For lightness values above B, the edit ensures it never exceeds a maximum lightness (A). The lightness scale ranges from 0 to 1, where 0 is black and 1 is fully white—unsuitable for a background.

You can review the transformation function here: Desmos Background Transformation Function and here Desmos Foreground Transformation Function.

UltimaDark also has the capability to edit pixels in images ("Image Edition" toggle), although this feature is currently experimental and not fully functional. An example of the broken functionality can be seen on the Apple support page: Broken Example. On the other hand, the feature works better on the Sushi Spirit website: Not-So-Bad Example.

Compatibility

Versions

Currently on 1.5.x

Downloads

Download from AMO (Firefox's add-on repository)

How To Clone

git clone https://github.com/ThomazPom/Moz-Ext-UltimaDark

Prerequisite

Bug Reporting

Bug reports help developers to find out about issues they may not have experienced - it is impossible to test an extension synthetically in every way that users will.

Backporting

Without an unreasonable level of effort, this extension will not be compatible with Pre-Quantum versions of Firefox (56 and lower). However, it should be theoretically possible to get working on 57 and higher (excluding the ImageEdition rewrite which requires Firefox 105 or above). Contributions towards this broader compatibility would be greatly appreciated.