Skip to content

Instantly share code, notes, and snippets.

@gauss256
Forked from Caster/script.user.js
Last active October 16, 2021 04:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gauss256/62e3bee214b1b6591c9dfb30ac2ba87d to your computer and use it in GitHub Desktop.
Save gauss256/62e3bee214b1b6591c9dfb30ac2ba87d 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"],
ignoreClass: "ql-editor",
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