Replies: 12 comments 42 replies
-
Can you please find the original dark theme issue filed and close this one? |
Beta Was this translation helpful? Give feedback.
-
Oh. I see. I'm on the mobile app. This is the discussion. |
Beta Was this translation helpful? Give feedback.
-
IMO, @mattiapontonio idea to fork mdn-minimalist makes more sense if we want something that can be merged upstream. |
Beta Was this translation helpful? Give feedback.
-
While I agree that a dark theme would be nice to have on MDN Web Docs. We need to consider all the use cases and people this would impact[1]. In the end, it needs to be driven by user choice via i.e. based on time of day, on an OS level, the system would have switched to dark mode but, for the moment you wish to disable dark mode. |
Beta Was this translation helpful? Give feedback.
-
Maybe at least we can start with dark theme for code examples, instead of writing a lot of code before deployment. |
Beta Was this translation helpful? Give feedback.
-
MDN burns my retinas, a dark mode toggle would be perfect. |
Beta Was this translation helpful? Give feedback.
-
Related request mdn/content#5272 |
Beta Was this translation helpful? Give feedback.
-
using this website is painful. it's 2021. add dark mode already. |
Beta Was this translation helpful? Give feedback.
-
I wrote a little user script that you can use with an addon script manager like Tampermonkey. This script basically loops over every DOM element, checks its background colour, and if the background colour is brighter than the specified limit, it will apply a formula to it that darkens it. I guess the biggest problem/concern is—it doesn't seem to be super fast, so there will be a flash of bright content before it gets dark. It doesn't look fantastic, but it will definitely darken most of the content. (For some reason it won't affect Here is the script: // ==UserScript==
// @name Dark Mode
// @namespace http://tampermonkey.net/
// @version 0.0.0-alpha.0
// @description A user script that darkens websites.
// @author msfninja
// @include *
// @grant none
// @run-at document-start
// ==/UserScript==
// Hide document while page is loading.
document.documentElement.style.backgroundColor = '#000f';
document.documentElement.style.opacity = '0';
// This variable sets the 'limit' of how bright a colour may be
// (a value from 0 to 255) before it's made darker. The sweetspot
// for a decent dark mode seems to be around 20. Setting it to 0
// will make every element black, and setting it to 255 will have
// no effect.
const max = 20;
// Here you can choose what elements should not be affected. You
// can specify classes, IDs or tag names (in the appropriate
// array, presumably).
const exclude = {
classNames: [
],
ids: [
],
tagNames: [
'input'
]
};
// Starting from here you should probably not touch anything.
// Threshold after which to darken a colour.
const threshold = Math.pow(max, 3);
const
// querySelectorAll
qa = selector => {
return document.querySelectorAll(selector);
},
// Checks for class containment.
contains = element => {
// Loop over all class names meant to be excluded.
exclude.classNames.forEach(className => {
// Does the supplied element contain an excluded class name?
if (element.classList.contains(className)) {
// Return `true`.
return true;
}
});
// Return `false`.
return false;
},
// Applies a darkening formula to a value.
darken = value => {
// Return a reduced value that's below the limit (`max`).
return Math.round(value / 255) * max;
},
// Generates an RGBA string.
generate = array => {
// Define colours.
let
red = darken(array[0]),
green = darken(array[1]),
blue = darken(array[2]),
// If there's an opacity specified, use it. Otherwise
// use '1' (maximum opacity).
alpha = array[3] ? array[3] : '1';
// Return an RGBA string.
return `rgba(${red}, ${green}, ${blue}, ${alpha})`;
};
// The thing that does the whole job.
const main = () => {
// A CSS string of rules
let css = `.bc-table, .bc-table * { background-color: #000f !important; color: #ffff !important; }`;
// Loop over all elements in <body>.
qa('*').forEach(element => {
// Is the element concerned not one of the excluded ones?
if (!(
contains(element) ||
exclude.ids.includes(element.id) ||
exclude.tagNames.includes(element.tagName.toLowerCase())
)) {
// Set element's colour to white.
element.style.color = 'rgba(255, 255, 255, 1)';
// Define some variables.
let
// The background of the current element
background = window.getComputedStyle(element).backgroundColor,
// RGBA array of the background's RGBA value
rgba = background.split(/[\(\))]/)[1].split(', '),
// The average value of the background
average = rgba[0] * rgba[1] * rgba[2];
// Is the average above the threshold?
if (average > threshold) {
// Generate an ID.
let id = `id${Math.random().toString().slice(2)}`
// Fingerprint the element.
element.classList.add(id);
// Add CSS rules.
css += `.${id} { background-color: ${generate(rgba)} !important; }`;
}
}
});
// Apply CSS rules.
let style = document.createElement('style');
if (style.styleSheet) {
style.styleSheet.cssText = css;
}
else {
style.appendChild(document.createTextNode(css));
}
document.head.appendChild(style);
}
// Wait until body is loaded.
document.body.onload = event => {
// Call `main`.
main();
// Unhide the document.
document.documentElement.style.opacity = '1';
} If someone knows how to optimise this code, I'd like to hear. |
Beta Was this translation helpful? Give feedback.
-
I'm +1 for a dark theme for any site or service, and I think that any website, program, etc. should offer a dark mode. For one of my web development contracts, I led the development of a user-switchable dark theme, defaulting to the value of the (As a current alternative, I have some custom CSS available at https://userstyles.world/style/1268/mozilla-developer-network-dark-theme -- hope you don't mind the shameless self-plug. :P) |
Beta Was this translation helpful? Give feedback.
-
Hi, I’ve just released an extension that adds a dark mode (with a toggle to choose between on o off, using |
Beta Was this translation helpful? Give feedback.
-
Just wanted to let everyone know that MDN is planning to incorporate a dark theme into their upcoming redesign, so soon there will be no more need for browser extensions and user CSS! |
Beta Was this translation helpful? Give feedback.
-
#2178
Example:
If the colors can be inverted they have a good contrast ➡️⬅️👁️
Beta Was this translation helpful? Give feedback.
All reactions