Skip to content

Instantly share code, notes, and snippets.

@wtfaremyinitials
Created July 17, 2016 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtfaremyinitials/4d9dbd02df6fe097452f6dad5ef64734 to your computer and use it in GitHub Desktop.
Save wtfaremyinitials/4d9dbd02df6fe097452f6dad5ef64734 to your computer and use it in GitHub Desktop.
Hack dark mode into websites
function handleProp(node, prop) {
var color = window.getComputedStyle(node)[prop];
if(color == "rgba(0, 0, 0, 0)")
return;
color = color.match(/rgba?\((\d+), (\d+), (\d+)/).splice(1,3);
if(color[0] == color[1] && color[1] == color[2]) {
node.style[prop] = "rgb(" + (256-color[0]) + ", " + (256-color[1]) + ", " + (256-color[2]) + ")";
}
}
function handle(node) {
handleProp(node, 'backgroundColor');
handleProp(node, 'color')
handleProp(node, 'borderTopColor')
handleProp(node, 'borderBottomColor')
handleProp(node, 'borderLeftColor')
handleProp(node, 'borderRightColor')
}
function trav(node) {
handle(node);
[].map.call(node.children, trav);
}
trav(document.body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment