Skip to content

Instantly share code, notes, and snippets.

@mreinstein
Last active March 4, 2024 18:45
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mreinstein/5360cac59a4304faf3cb5c7234eaf12b to your computer and use it in GitHub Desktop.
Save mreinstein/5360cac59a4304faf3cb5c7234eaf12b to your computer and use it in GitHub Desktop.
invert all colors on a web page
// invert all colors on the page
export default function invert() {
let 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')
if (!window.counter) {
window.counter = 1
} else {
window.counter++
if (window.counter % 2 == 0) {
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))
}
head.appendChild(style)
}
@ATLAS-IND-Software
Copy link

what module do i need to run this shit

@mreinstein
Copy link
Author

@ATLAS-IND-Software I'm not sure what you mean, can you elaborate? This isn't published as an official module anywhere, it's just a gist I was using to experiment with inverting all colors on a website. It does work though.

@drhouse
Copy link

drhouse commented Jan 22, 2022

confirmed does work, removed 'export default' and added 'invert()'
cheers

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