Created
August 10, 2020 16:56
-
-
Save juanmalunatic/0e592515641458fd5ea2c493b16af090 to your computer and use it in GitHub Desktop.
Toggle MathJax to copy EdX equations to Anki
This file contains hidden or 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
// Based on https://github.com/mathjax/mathjax-docs/wiki/Obtaining-the-original-TeX-from-a-rendered-page | |
function removeTypeset() { | |
var HTML = MathJax.HTML, jax = MathJax.Hub.getAllJax(); | |
for (var i = 0, m = jax.length; i < m; i++) { | |
var script = jax[i].SourceElement(), tex = jax[i].originalText; | |
if (script.type.match(/display/)) {tex = "\\["+tex+"\\]"} else {tex = "\\("+tex+"\\)"} | |
jax[i].Remove(); | |
var preview = script.previousSibling; | |
if (preview && preview.className === "MathJax_Preview") { | |
preview.parentNode.removeChild(preview); | |
} | |
preview = HTML.Element("span",{className:"MathJax_Preview"},[tex]); | |
script.parentNode.insertBefore(preview,script); | |
} | |
} | |
function showTypeset(show) { | |
MathJax.Hub.Queue(show ? ["Reprocess",MathJax.Hub] : removeTypeset); | |
} | |
function on() { | |
showTypeset(true); | |
} | |
function off() { | |
showTypeset(false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should paste the code in the console and then run "off()" or "on()" as needed.
Would be cool to create a hotkey using Greasemonkey.