Skip to content

Instantly share code, notes, and snippets.

@malkafly
Created December 11, 2017 12:03
Show Gist options
  • Save malkafly/d548cdf45c7e11ae63964fcb40054ace to your computer and use it in GitHub Desktop.
Save malkafly/d548cdf45c7e11ae63964fcb40054ace to your computer and use it in GitHub Desktop.
Invert color of all elements
javascript: (
function () {
//based on https://stackoverflow.com/questions/4766201/javascript-invert-color-on-all-elements-of-a-page
// the css we are going to inject
var css = 'html {-webkit-filter: invert(100%);' +
'-moz-filter: invert(100%);' +
'-o-filter: invert(100%);' +
'-ms-filter: invert(100%); }',
head = document.getElementsByTagName('head')[0],
style = document.createElement('style');
// a hack, so you can "invert back" clicking the bookmarklet again
if (!window.counter) { window.counter = 1;} else { window.counter ++;
if (window.counter % 2 == 0) { var css ='html {-webkit-filter: invert(0%); -moz-filter: invert(0%); -o-filter: invert(0%); -ms-filter: invert(0%); }'}
};
style.type = 'text/css';
if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
//injecting the css to the head
head.appendChild(style);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment