Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
GreaseMonkey script for rendering ChatJax automatically on chat sites (like Physics or Math)
// ==UserScript==
// @name ChatJax
// @namespace
// @description Rendering ChatJax
// @include*
// @author Bass
// @license Beerware
// @version 1
// @grant GM_addStyle
// ==/UserScript==
function main() {
window.doChatJax = function () {
window.setTimeout(doChatJax, 2000);
if (window.MathJax === undefined) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '';
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);
Copy link

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.

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"

Copy link

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