Last active
August 26, 2021 17:12
-
-
Save vyznev/d0c338f0f9dbec43e313794299063b60 to your computer and use it in GitHub Desktop.
User script to disable MathJax display math in comments on Stack Exchange sites
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 Disable display math in comments | |
// @namespace https://github.com/vyznev/ | |
// @description Forces all MathJax elements in comments to be rendered inline | |
// @author Ilmari Karonen | |
// @version 1.1 | |
// @match *://*.stackexchange.com/* | |
// @match *://*.mathoverflow.net/* | |
// @homepageURL http://meta.math.stackexchange.com/questions/23250/disable-display-math-in-comments | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
var inject = function () { | |
MathJax.Hub.Register.MessageHook( "Begin Process", function (message) { | |
var elements = message[1]; | |
var selector = '.comment script[type="math/tex; mode=display"]'; | |
$(elements).find(selector).attr('type', 'math/tex'); | |
} ); | |
}; | |
var script = document.createElement('script'); | |
script.type = 'text/x-mathjax-config'; | |
script.textContent = "(" + inject + ")();"; | |
var parent = (document.head || document.documentElement); | |
if (parent) parent.appendChild(script); | |
else { | |
// work-around for https://github.com/greasemonkey/greasemonkey/issues/2996 | |
var obs = new MutationObserver(function () { | |
var parent = (document.head || document.documentElement); | |
if (parent) { obs.disconnect(); parent.appendChild(script); } | |
}); | |
obs.observe(document, {childList: true}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment