Skip to content

Instantly share code, notes, and snippets.

@jasonleonhard
Last active July 10, 2024 02:47
Show Gist options
  • Save jasonleonhard/301d277a8684c0a9f79d to your computer and use it in GitHub Desktop.
Save jasonleonhard/301d277a8684c0a9f79d to your computer and use it in GitHub Desktop.
Invert colors in Chrome Browser (with DevTools JavaScript console)
javascript: (function () {
// 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) {
// showing another way instead of multiple strings with + you can use \
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);
})();
@jasonleonhard
Copy link
Author

jasonleonhard commented Nov 25, 2021

Bookmarklets tend to be one line of code. If you add them to a bookmark, replacing the url of a bookmark for anything, they replace things like spaces with the %.... and similar.

@eliasstassinopoulos
Copy link

This is very cool. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment