Last active
March 18, 2025 15:32
-
-
Save jasonleonhard/301d277a8684c0a9f79d to your computer and use it in GitHub Desktop.
Invert colors in Chrome Browser (with DevTools JavaScript console)
This file contains hidden or 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
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); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is very cool. Thank you.