Hackernews Darkmode
Courtesy of https://github.com/susam/userscripts and thanks to chatgpt for fixing the flashing issue
Install this custom script with TamperMonkey.
// ==UserScript==
// @name Dark HN
// @match https://news.ycombinator.com/*
// @run-at document-start
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Create a style element
const style = document.createElement('style');
style.innerHTML = `
body {
background: #111 !important;
filter: saturate(0) invert(1) hue-rotate(180deg) !important;
}
td {
background: #ccc !important;
}
img {
filter: saturate(0) !important;
}
`;
// Append the style element to the head
const head = document.head || document.getElementsByTagName('head')[0];
if (head) {
head.appendChild(style);
} else {
// If the head element is not available yet, use a MutationObserver to wait for it
new MutationObserver((mutations, observer) => {
const head = document.head || document.getElementsByTagName('head')[0];
if (head) {
head.appendChild(style);
observer.disconnect();
}
}).observe(document.documentElement, { childList: true, subtree: true });
}
})();