1 | # Dark Reader for Google Chrome, Microsoft Edge and Mozilla Firefox
|
2 |
|
3 | ![Dark Reader screenshot](https://i.imgur.com/DyBlYwU.png)
|
4 |
|
5 | This extension **inverts brightness** of web pages and aims to **reduce eyestrain** while you browse the web.
|
6 | Visit [Edge Addons](https://microsoftedge.microsoft.com/addons/detail/dark-reader/ifoakfbpdcdoeenechcleahebpibofpc), [Chrome Web Store](https://chrome.google.com/webstore/detail/dark-reader/eimadpbcbfnmbkopoojfekhnkhdbieeh)
|
7 | and [Firefox Add-ons](https://addons.mozilla.org/en-US/firefox/addon/darkreader/)
|
8 | for more info.
|
9 |
|
10 | ## How to contribute
|
11 |
|
12 | ### Sponsor
|
13 |
|
14 | [Donate](https://opencollective.com/darkreader) via Open Collective.
|
15 |
|
16 | ### Translate
|
17 |
|
18 | [Improve or suggest](https://github.com/darkreader/darkreader/tree/master/src/_locales) a translation.
|
19 | See the list of [language codes](https://developer.chrome.com/webstore/i18n#localeTable) that we can support.
|
20 |
|
21 | ### Fix a wrong inversion
|
22 |
|
23 | If a website is **already dark** (has all pages dark by default), you can **add it to the [dark-sites.config](https://github.com/alexanderby/darkreader/blob/master/src/config/dark-sites.config) file**
|
24 | *(please, preserve alphabetical order)*.
|
25 |
|
26 | If some **parts** of a web page are **wrongly inverted**,
|
27 | you can fix this by specifying appropriate [**CSS selectors**](https://developer.mozilla.org/docs/Web/CSS/CSS_Selectors) in
|
28 | **[dynamic-theme-fixes.config](https://github.com/alexanderby/darkreader/blob/master/src/config/dynamic-theme-fixes.config)**
|
29 | (for Dynamic Theme mode)
|
30 | or **[inversion-fixes.config](https://github.com/alexanderby/darkreader/blob/master/src/config/inversion-fixes.config)**
|
31 | (for Filter and Filter+ modes)
|
32 | *(please, preserve alphabetical order by URL, use short selectors, and preserve code style)*.
|
33 |
|
34 | Automatically syncing the above files to every Dark Reader user was disabled because the GitHub team doesn't allow using GitHub as a CDN. Storing these files and making requests to other resources would be expensive and look suspicious. As such, changes are included with each new Dark Reader release.
|
35 |
|
36 | ### Use Dev Tools
|
37 |
|
38 | Dev Tools is designed to **fix minor issues** on a web page
|
39 | *(like dark icon on dark background, removing bright background, adding white background to transparent image, etc.)*.
|
40 | If the page looks partially dark and bright in **Dynamic mode**, we consider it a bug.
|
41 | For **Filter mode**, it is a common practice to invert already dark page parts.
|
42 |
|
43 | - Open **Chrome Dev Tools** (F12) in Chrome or "Inspector" (Ctrl+Shift+C) in Firefox.
|
44 | - Click on **element picker** (top-left corner). It is enabled automatically in Firefox.
|
45 | - Pick wrongly inverted element.
|
46 | - Choose a **[selector](https://developer.mozilla.org/docs/Web/CSS/CSS_Selectors)** for that element or all similar elements (e.g. if element has `class="icon small"`, selector may look like `.icon`).
|
47 | - Click **Dark Reader icon**.
|
48 | - Click **Open developer tools** (at bottom of Dark Reader popup).
|
49 | - Edit or add a block containing the URL and selectors to invert.
|
50 | - Click **Apply**.
|
51 | - Check how it looks both in **Light** and **Dark** mode.
|
52 | - If the **fix works** open
|
53 | **[dynamic-theme-fixes.config](https://github.com/alexanderby/darkreader/blob/master/src/config/dynamic-theme-fixes.config) file**
|
54 | or **[inversion-fixes.config](https://github.com/alexanderby/darkreader/blob/master/src/config/inversion-fixes.config) file**.
|
55 | - Click **Edit** (login to GitHub first).
|
56 | - **Insert your fix** there. Preserve **alphabetic order** by URL.
|
57 | - Provide a **short description** of what you have done.
|
58 | - Click **Propose file change**.
|
59 | - Review your changes. Click **Create pull request**.
|
60 | - The Travis CI will run tests reviewing your changes.
|
61 | - If you see a **red cross** click **Details** to see what is wrong and edit the existing Pull Request.
|
62 | - When you see a **green checkmark** then everything is fine.
|
63 | - Dark Reader developer will **review** and merge your changes, making them available to all users.
|
64 |
|
65 | ```
|
66 | dynamic-theme-fixes.config
|
67 | ================================
|
68 |
|
69 | example.com
|
70 |
|
71 | INVERT
|
72 | .icon
|
73 |
|
74 | CSS
|
75 | .wrong-element-colors {
|
76 | background-color: ${white} !important;
|
77 | color: ${black} !important;
|
78 | }
|
79 |
|
80 | IGNORE INLINE STYLE
|
81 | .color-picker
|
82 |
|
83 | IGNORE IMAGE ANALYSIS
|
84 | .logo
|
85 | ```
|
86 |
|
87 | - `INVERT` rule inverts specified elements.
|
88 | For **Dynamic mode** use `INVERT` only for dark images that are invisible on dark backgrounds (icons, diagrams, charts, `<img>` and `<svg>` elements).
|
89 | - `CSS` rule adds custom CSS to a web page.
|
90 | `!important` keyword should be specified for each CSS property to prevent overrides by other stylesheets.
|
91 | **Dynamic mode** supports `${COLOR}` template, where `COLOR` is a color value before the inversion (`white` will become `black` in dark mode).
|
92 | - `IGNORE INLINE STYLE` rule will prevent inline style analysis of matched elements
|
93 | (e.g. for `<p style="color: red">` element's `style` attribute will not be changed).
|
94 | - `IGNORE IMAGE ANALYSIS` rule will prevent background images from being analyzed for matched selectors.
|
95 |
|
96 | #### Dynamic variables
|
97 |
|
98 | When making a fix for background or text colors,
|
99 | instead of using hardcoded colors (like `#fff`, `#000`, `black` or `white`),
|
100 | please use CSS variables that are generated based on user settings:
|
101 |
|
102 | ```
|
103 | dynamic-theme-fixes.config
|
104 | ================================
|
105 | example.com
|
106 |
|
107 | CSS
|
108 | .logo {
|
109 | background-color: var(--darkreader-neutral-background);
|
110 | }
|
111 | .footer > p {
|
112 | color: var(--darkreader-neutral-text);
|
113 | }
|
114 |
|
115 | ```
|
116 |
|
117 | Here is a full list of available CSS variables:
|
118 |
|
119 | - `--darkreader-neutral-background` should be mostly used for elements that have a wrong background color (usually bright backgrounds that should be dark).
|
120 | - `--darkreader-neutral-text` should be used for elements with a wrong text color (usually dark texts that should be light).
|
121 | - `--darkreader-selection-background` corresponds to user's Selection Background Color setting.
|
122 | - `--darkreader-selection-text` corresponds to user's Selection Text Color setting.
|
123 |
|
124 | #### Fixes for Filter and Filter+ modes
|
125 |
|
126 | ```
|
127 | inversion-fixes.config
|
128 | ================================
|
129 |
|
130 | example.com
|
131 |
|
132 | INVERT
|
133 | .icon
|
134 | .button
|
135 | #player
|
136 |
|
137 | NO INVERT
|
138 | #player *
|
139 |
|
140 | REMOVE BG
|
141 | .bg-photo
|
142 |
|
143 | CSS
|
144 | .overlay {
|
145 | background: rgba(255, 255, 255, 0.5);
|
146 | }
|
147 | ```
|
148 |
|
149 | - Filter and Filter+ work by inverting the whole web page and reverting necessary parts (images, videos, etc.), listed in the `INVERT` section.
|
150 | - If an inverted element contains images or other content that becomes wrongly displayed, `NO INVERT` rule can be used.
|
151 | - `REMOVE BG` removes the background image from an element and forces a black background.
|
152 |
|
153 | ### Add new features or fix bugs
|
154 |
|
155 | If you would like to **add new feature** to Dark Reader or **fix a bug**, **submit an issue** in GitHub (if there is no existing one), **discuss** it with active contributors, and wait for **approval**.
|
156 |
|
157 | To build and debug the extension **install the [Node.js](https://nodejs.org/)** LTS.
|
158 | Install development dependencies by running `npm install` in the project root folder.
|
159 | Then execute `npm run debug`.
|
160 |
|
161 | #### Chrome and Edge
|
162 |
|
163 | - Open the `chrome://extensions` page.
|
164 | - Disable the official Dark Reader version.
|
165 | - Enable the **Developer mode**.
|
166 | - Click **Load unpacked extension** button
|
167 | - Navigate to the project's `debug/` folder.
|
168 |
|
169 | #### Firefox
|
170 |
|
171 | - Open the `about:addons` page.
|
172 | - Disable the official Dark Reader version.
|
173 | - Open `about:debugging#addons` page.
|
174 | - Click **Load Temporary Add-on** button
|
175 | - Open the `debug-firefox/manifest.json` file.
|
176 |
|
177 | If you want the project to be automatically recompiled after making code changes,
|
178 | run `npm run debug-watch` instead of `npm run debug`.
|
179 |
|
180 | For editing the code you can use any text editor or web IDE (like [Visual Studio Code](https://code.visualstudio.com), [Atom](https://atom.io/), or [WebStorm](https://www.jetbrains.com/webstorm/)).
|
181 |
|
182 | **Please preserve code style** (whitespaces etc).
|
183 |
|
184 | Run tests by executing `npm test`.
|
185 |
|
186 | Submit a **pull request**, and wait for **review**.
|
187 |
|
188 | ## Building for use
|
189 |
|
190 | You can install the extension from a file.
|
191 | Install [Node.js LTS](https://nodejs.org/en/). Download the source code (or check out from git).
|
192 | Open terminal in root folder and run:
|
193 |
|
194 | - `npm install`
|
195 | - `npm run build`
|
196 |
|
197 | This will generate `build.zip` for use in Chromium browsers and `build-firefox.xpi` for use in Firefox.
|
198 |
|
199 | ## Using for a website
|
200 |
|
201 | You can use Dark Reader to enable dark mode on your website!
|
202 |
|
203 | - Install the package from NPM (`npm install darkreader`)
|
204 | - or build from the source code (`npm run api`)
|
205 | - or include the script via a CDN such as [unpkg](https://unpkg.com/darkreader/) or [jsDelivr](https://www.jsdelivr.com/package/npm/darkreader)
|
206 |
|
207 | Then use the following API
|
208 |
|
209 | ```javascript
|
210 | DarkReader.enable({
|
211 | brightness: 100,
|
212 | contrast: 90,
|
213 | sepia: 10
|
214 | });
|
215 |
|
216 | DarkReader.disable();
|
217 |
|
218 | // Enable when system color scheme is dark.
|
219 | DarkReader.auto({
|
220 | brightness: 100,
|
221 | contrast: 90,
|
222 | sepia: 10
|
223 | });
|
224 |
|
225 | // Stop watching for system color scheme.
|
226 | DarkReader.auto(false);
|
227 |
|
228 | // Get the generated CSS of Dark Reader returned as a string.
|
229 | const CSS = await DarkReader.exportGeneratedCSS();
|
230 |
|
231 | // Check if Dark Reader is enabled.
|
232 | const isEnabled = DarkReader.isEnabled();
|
233 | ```
|
234 |
|
235 | ... or if you are using ES modules
|
236 |
|
237 | ```javascript
|
238 | import {
|
239 | enable as enableDarkMode,
|
240 | disable as disableDarkMode,
|
241 | auto as followSystemColorScheme,
|
242 | exportGeneratedCSS as collectCSS,
|
243 | isEnabled as isDarkReaderEnabled
|
244 | } from 'darkreader';
|
245 |
|
246 | enableDarkMode({
|
247 | brightness: 100,
|
248 | contrast: 90,
|
249 | sepia: 10,
|
250 | });
|
251 |
|
252 | disableDarkMode();
|
253 |
|
254 | followSystemColorScheme();
|
255 |
|
256 | const CSS = await collectCSS();
|
257 |
|
258 | const isEnabled = isDarkReaderEnabled();
|
259 | ```
|
260 |
|
261 | ## Contributors
|
262 |
|
263 | This project exists thanks to all the people who contribute!
|
264 |
|
265 | <a href="../../graphs/contributors"><img src="https://opencollective.com/darkreader/contributors.svg?width=890&button=false" /></a>
|
266 |
|
267 | ## Backers
|
268 |
|
269 | Thank you to all our generous backers!
|
270 |
|
271 | <a href="https://opencollective.com/darkreader#backers" target="_blank"><img src="https://opencollective.com/darkreader/backers.svg?width=890"></a>
|
272 |
|
273 | ## Sponsors
|
274 |
|
275 | Support this project by [becoming a sponsor](https://opencollective.com/darkreader#sponsor). Thank you to our wonderful sponsors!
|
276 |
|
277 | <a href="https://opencollective.com/darkreader/sponsor/0/website" target="_blank"><img src="https://opencollective.com/darkreader/sponsor/0/avatar.svg"></a>
|
278 | <a href="https://opencollective.com/darkreader/sponsor/1/website" target="_blank"><img src="https://opencollective.com/darkreader/sponsor/1/avatar.svg"></a>
|
279 | <a href="https://opencollective.com/darkreader/sponsor/2/website" target="_blank"><img src="https://opencollective.com/darkreader/sponsor/2/avatar.svg"></a>
|
280 | <a href="https://opencollective.com/darkreader/sponsor/3/website" target="_blank"><img src="https://opencollective.com/darkreader/sponsor/3/avatar.svg"></a>
|
281 | <a href="https://opencollective.com/darkreader/sponsor/4/website" target="_blank"><img src="https://opencollective.com/darkreader/sponsor/4/avatar.svg"></a>
|
282 | <a href="https://opencollective.com/darkreader/sponsor/5/website" target="_blank"><img src="https://opencollective.com/darkreader/sponsor/5/avatar.svg"></a>
|
283 | <a href="https://opencollective.com/darkreader/sponsor/6/website" target="_blank"><img src="https://opencollective.com/darkreader/sponsor/6/avatar.svg"></a>
|
284 | <a href="https://opencollective.com/darkreader/sponsor/7/website" target="_blank"><img src="https://opencollective.com/darkreader/sponsor/7/avatar.svg"></a>
|
285 | <a href="https://opencollective.com/darkreader/sponsor/8/website" target="_blank"><img src="https://opencollective.com/darkreader/sponsor/8/avatar.svg"></a>
|
286 | <a href="https://opencollective.com/darkreader/sponsor/9/website" target="_blank"><img src="https://opencollective.com/darkreader/sponsor/9/avatar.svg"></a>
|