Skip to content

Instantly share code, notes, and snippets.

@Caster
Last active December 26, 2017 11:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Caster/fcd6b0444b06ea3f5fe565e295a80611 to your computer and use it in GitHub Desktop.
Save Caster/fcd6b0444b06ea3f5fe565e295a80611 to your computer and use it in GitHub Desktop.
A GreaseMonkey/TamperMonkey version of the `math-with-slack` script.
// ==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);
});
@gauss256
Copy link

gauss256 commented Jun 4, 2017

In my fork I added a line

ignoreClass: "ql-editor",

which fixes problems with the editing behavior. The issue is the same as for the desktop client, as described here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment