Skip to content

Instantly share code, notes, and snippets.

@bassup
Last active August 11, 2017 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bassup/93f78c0fac2a7be25086 to your computer and use it in GitHub Desktop.
Save bassup/93f78c0fac2a7be25086 to your computer and use it in GitHub Desktop.
GreaseMonkey script for rendering ChatJax automatically on stackexchange.com chat sites (like Physics or Math)
// ==UserScript==
// @name ChatJax
// @namespace http://stackexchange.com/
// @description Rendering ChatJax
// @include http://chat.stackexchange.com/*
// @author Bass
// @license Beerware
// @version 1
// @grant GM_addStyle
// ==/UserScript==
function main() {
window.doChatJax = function () {
window.setTimeout(doChatJax, 2000);
window.MathJax.Hub.Queue(['Typeset',window.MathJax.Hub]);
};
if (window.MathJax === undefined) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML';
var config = 'MathJax.Hub.Config({' + 'extensions: ["tex2jax.js"],' + 'tex2jax: { inlineMath: [["$","$"],["\\\\\\\\\\\\(","\\\\\\\\\\\\)"]], displayMath: [["$$","$$"],["\\\\[","\\\\]"]], processEscapes: true },' + 'jax: ["input/TeX","output/HTML-CSS"]' + '});' + 'MathJax.Hub.Startup.onload();';
if (window.opera) {
script.innerHTML = config
} else {
script.text = config
}
document.getElementsByTagName('head') [0].appendChild(script);
window.setTimeout(doChatJax, 500);
}
};
var script = document.createElement('script');
script.appendChild(document.createTextNode('('+ main +')();'));
(document.body || document.head || document.documentElement).appendChild(script);
@bassup
Copy link
Author

bassup commented Jan 12, 2016

How to install:

  • If you don't have it yet, you need the GreaseMonkey extension for Firefox or TamperMonkey for Chrome. IE users have to try Trixie, and for Safari users there's GreaseKit, but I don't know if this script works in IE or Safari.
  • On the github website, click on the "Raw" button above the code.
  • After a browser restart you should see MathJax rendered automatically. If it doesn't work, write a message to @bass in the PSE chat.

@diazona
Copy link

diazona commented Jan 12, 2016

I think if you give it a name ending in .user.js, it will be possible to automatically install it by just clicking on "Raw"

@bassup
Copy link
Author

bassup commented Jan 12, 2016

Cool, didn't know that.

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