Last active
December 26, 2017 11:34
-
-
Save Caster/fcd6b0444b06ea3f5fe565e295a80611 to your computer and use it in GitHub Desktop.
A GreaseMonkey/TamperMonkey version of the `math-with-slack` script.
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
// ==UserScript== | |
// @name MathJax on Slack | |
// @namespace https://github.com/fsavje/math-with-slack | |
// @description Renders math on Slack using MathJax. Based on github:fsavje/math-with-slack. | |
// @include https://*.slack.com/messages/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
// See: https://github.com/fsavje/math-with-slack | |
window.addEventListener('load', function() { | |
var mathjax_config = document.createElement("script"); | |
mathjax_config.type = "text/x-mathjax-config"; | |
mathjax_config.text = ` | |
MathJax.Hub.Config({ | |
messageStyle: "none", | |
extensions: ["tex2jax.js"], | |
jax: ["input/TeX", "output/HTML-CSS"], | |
tex2jax: { | |
skipTags: ["script","noscript","style","textarea","pre","code"], | |
inlineMath: [ ['\$','\$'] ], | |
displayMath: [ ['\$\$','\$\$'] ], | |
processEscapes: true | |
}, | |
TeX: { | |
extensions: ["noErrors.js", "noUndefined.js"] | |
} | |
}); | |
`; | |
var mathjax_script = document.createElement("script"); | |
mathjax_script.type = "text/javascript"; | |
mathjax_script.src = "https://cdn.mathjax.org/mathjax/latest/MathJax.js"; | |
document.getElementsByTagName("head")[0].appendChild(mathjax_config); | |
document.getElementsByTagName("head")[0].appendChild(mathjax_script); | |
var render = function(records, observer) { | |
MathJax.Hub.Queue(["Typeset", MathJax.Hub]); | |
}, | |
target = document.querySelector('#msgs_div'), | |
observer = new MutationObserver(render), | |
config = { attributes: false, childList: true, characterData: true, subtree: true }; | |
observer.observe(target, config); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In my fork I added a line
which fixes problems with the editing behavior. The issue is the same as for the desktop client, as described here.