Skip to content

Instantly share code, notes, and snippets.

@arnav-t
Created September 16, 2021 05:42
Show Gist options
  • Save arnav-t/6f2de3e969eb9640f822b528b4571057 to your computer and use it in GitHub Desktop.
Save arnav-t/6f2de3e969eb9640f822b528b4571057 to your computer and use it in GitHub Desktop.
CF DarkReader Tex Formulae Inversion
// ==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