Created
September 19, 2022 09:35
-
-
Save kaichii/302eb8c58b5c75f35d28436a21df9d1e to your computer and use it in GitHub Desktop.
Fix wiki broken latex
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 Wiki Latex Fixer | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Fix wiki broken latex | |
// @author kaichi | |
// @match https://*.wikipedia.org/** | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=wikipedia.org | |
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js | |
// @resource KatexCSS https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css | |
// @grant GM_xmlhttpRequest | |
// @grant GM_getResourceText | |
// @grant GM_addStyle | |
// @run-at document-start | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
GM_xmlhttpRequest({ | |
method : "GET", | |
url : "https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js", | |
onload : (ev) => | |
{ | |
let e = document.createElement('script'); | |
e.innerText = ev.responseText; | |
document.head.appendChild(e); | |
} | |
}); | |
const KatexCSS = GM_getResourceText("KatexCSS"); | |
GM_addStyle(KatexCSS); | |
function renderLatex(content, element){ | |
katex.render(String.raw`${content}`, element); | |
} | |
setInterval(function(){ | |
const images = [...document.querySelectorAll('.mwe-math-fallback-image-inline[src^="https://wikimedia.org/api/rest_v1/media/math/render/svg"]'), ...document.querySelectorAll('.mwe-math-fallback-image-display[src^="https://wikimedia.org/api/rest_v1/media/math/render/svg"]')]; | |
for(let image of images){ | |
renderLatex(image.alt, image.parentNode); | |
} | |
}, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment