Created
May 24, 2020 09:04
-
-
Save sneakyness/4fc195912152827a3499f7bf38590aa1 to your computer and use it in GitHub Desktop.
Chrome/Brave PDF Viewer Dark Mode Toggle
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
// 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(); |
Do you know how I can turn this script into a bookmarklet in Brave?
Thanks for this snippet! I found out that using background-color: #dddddd
is better for the eyes. The whites are not (255, 255, 255) and the blacks are not (0, 0, 0) which makes it a bit easier on the eyes. You'll thank me later. 😉
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you know how I can turn this script into a bookmarklet in Brave?