Created
September 16, 2021 05:42
-
-
Save arnav-t/6f2de3e969eb9640f822b528b4571057 to your computer and use it in GitHub Desktop.
CF DarkReader Tex Formulae Inversion
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 CF DarkReader invert Tex Formulae | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://codeforces.com/* | |
// @icon https://www.google.com/s2/favicons?domain=codeforces.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
window.addEventListener('load', () => { | |
// Update callback | |
const update = () => { | |
let invert = 100; | |
if (document.documentElement.getAttribute('data-darkreader-scheme') !== 'dark') invert = 0; | |
document.querySelectorAll('img.tex-formula').forEach((el) => el.style.filter = `invert(${invert}%)`); | |
}; | |
// Initial update | |
update(); | |
// Mutation observer | |
const htmlTag = document.documentElement; | |
const observer = new MutationObserver(update); | |
observer.observe(htmlTag, {attributes: true, attributeFilter: ['data-darkreader-scheme']}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment