Last active
July 1, 2024 13:10
-
-
Save iqiancheng/9945010cc85209185618c964bdd84fd1 to your computer and use it in GitHub Desktop.
LaTeX Cleanup UserScript for arXiv
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 arXiv LaTeX Zapper.user.js | |
// @namespace https://gist.github.com/iqiancheng | |
// @author qian.cheng | |
// @version 0.3 | |
// @description Zap those pesky LaTeX elements that snuck into the HTML on arXiv | |
// @downloadURL https://gist.githubusercontent.com/iqiancheng/9945010cc85209185618c964bdd84fd1/raw/969a26e502d4487569a561013612eb6b019bfb1b/arxiv_latex_zapper.user.js | |
// @updateURL https://gist.githubusercontent.com/iqiancheng/9945010cc85209185618c964bdd84fd1/raw/969a26e502d4487569a561013612eb6b019bfb1b/arxiv_latex_zapper.user.js | |
// @match *://ar5iv.labs.arxiv.org/html/* | |
// @match *://arxiv.org/html/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function nukeLatexElements() { | |
// This regex is our LaTeX-spotting superpower | |
const latexPattern = /\\newfloatcommand|capbtabboxtable\s*\[\s*\]\s*\[|\\FBwidth/; | |
// Round up all the <p> and <span> suspects | |
const elements = document.querySelectorAll('p, span'); | |
elements.forEach(element => { | |
// Is this element harboring LaTeX fugitives? | |
if (latexPattern.test(element.textContent)) { | |
// Caught red-handed! Time to disappear | |
element.remove(); | |
console.log('Busted and removed:', element.textContent); | |
} | |
}); | |
} | |
// Fire up our LaTeX cleanup crew when the page loads | |
window.addEventListener('load', nukeLatexElements); | |
// Set up a stakeout for any sneaky, late-arriving LaTeX | |
const observer = new MutationObserver(nukeLatexElements); | |
observer.observe(document.body, { childList: true, subtree: true }); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment