Skip to content

Instantly share code, notes, and snippets.

@tillahoffmann
Created January 19, 2014 20:26
Show Gist options
  • Save tillahoffmann/8510540 to your computer and use it in GitHub Desktop.
Save tillahoffmann/8510540 to your computer and use it in GitHub Desktop.
This is a modification of the script provided by Davide Cervone (http://stackoverflow.com/questions/11255900/mathjax-support-in-github-using-a-chrome-browser-plugin). The script URL is modified to load the script from *.github.com* in order to comply with the new [Content Security Policies](https://github.com/blog/1477-content-security-policy).
// ==UserScript==
// @name Run MathJax in Github or Bitbucket
// @namespace http://www.mathjax.org/
// @description Runs MathJax on any page in github.com or bitbucket.org
// @include http://github.com/*
// @include https://github.com/*
// @include http://bitbucket.org/*
// @include https://bitbucket.org/*
// ==/UserScript==
/*****************************************************************/
(function () {
function LoadMathJax() {
if (!window.MathJax) {
if (document.body.innerHTML.match(/$|\\\[|\\\(|<([a-z]+:)math/)) {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://raw.github.com/mathjax/MathJax/master/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
script.text = [
"MathJax.Hub.Config({",
" tex2jax: {inlineMath: [['$','$'],['\\\\\(','\\\\\)']]}",
"});"
].join("\n");
var parent = (document.head || document.body || document.documentElement);
parent.appendChild(script);
}
}
};
var script = document.createElement("script");
script.type = "text/javascript";
script.text = "(" + LoadMathJax + ")()";
var parent = (document.head || document.body || document.documentElement);
setTimeout(function () {
parent.appendChild(script);
parent.removeChild(script);
},0);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment