Skip to content

Instantly share code, notes, and snippets.

@mreinstein
Last active June 12, 2024 06:12
Show Gist options
  • Select an option

  • Save mreinstein/5360cac59a4304faf3cb5c7234eaf12b to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

what module do i need to run this shit

@mreinstein
Copy link
Copy Markdown
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
Copy Markdown

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