Skip to content

Instantly share code, notes, and snippets.

@sneakyness
Created May 24, 2020 09:04
Show Gist options
  • Save sneakyness/4fc195912152827a3499f7bf38590aa1 to your computer and use it in GitHub Desktop.
Save sneakyness/4fc195912152827a3499f7bf38590aa1 to your computer and use it in GitHub Desktop.
Chrome/Brave PDF Viewer Dark Mode Toggle
// When using in-browser PDF viewer, you can inspect it and run this in the console
// It's using CSS Blending to invert the colors of the PDF
function togglePDFDarkMode() {
var cover = document.createElement("div");
let inversion = `
position: fixed;
pointer-events: none;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: white;
mix-blend-mode: difference;
z-index: 1;
`
if (document.body.contains(cover)) {
document.body.removeChild(cover);
} else {
cover.setAttribute("style", inversion);
document.body.appendChild(cover);
}
}
togglePDFDarkMode();
@Christian-Kouts
Copy link

Do you know how I can turn this script into a bookmarklet in Brave?

@RadiumRC
Copy link

Do you know how I can turn this script into a bookmarklet in Brave?

https://caiorss.github.io/bookmarklet-maker/

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