Created
July 17, 2016 15:56
-
-
Save wtfaremyinitials/4d9dbd02df6fe097452f6dad5ef64734 to your computer and use it in GitHub Desktop.
Hack dark mode into websites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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