Created
March 11, 2022 13:47
-
-
Save jeansordes/d31b0ed82bbe9270808086763d71d2d3 to your computer and use it in GitHub Desktop.
Toggle dark mode
This file contains 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
// ==UserScript== | |
// @name Night mode | |
// @version 0.0.1 | |
// @description Toggle night mode by typing ALT + N | |
// @match *://*/* | |
// @source https://gist.github.com/jeansordes | |
// ==/UserScript== | |
function nightmode() { | |
'use strict'; | |
const d = document; | |
let t = 'nightstyle-549ad_p', s = 'stylish-1', _ = '#'; | |
try { | |
d.querySelectorAll('iframe').forEach(i => i.contentWindow.document.querySelector(_ + s)?.remove()); | |
} catch(e) { console.log(e); } | |
if (d.querySelector(_ + s)) { | |
d.querySelector(_ + s).remove(); | |
} | |
if (d.querySelector(_ + t)) { | |
d.querySelector(_ + t).parentElement.remove(); | |
} else { | |
d.head.appendChild(d.createElement('div')).innerHTML = '<style id="' + t + '">html{filter: invert(0.9) hue-rotate(180deg)}img,video,[style*="background-image: url("]{filter: invert(1) hue-rotate(180deg) brightness(1.2)}body {background: white}</style>'; | |
}; | |
} | |
document.addEventListener("keydown",evt => { | |
// if((evt.altKey && evt.key.toLowerCase() == 'n') || evt.key.toLowerCase() == 'altgraph') { | |
if((evt.altKey && evt.key.toLowerCase() == 'n')) { | |
nightmode(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment