mathe172 / MathJax for Wikispaces

// ==UserScript==
// @name       MathJax for Wikispaces
// @namespace  
// @version		2.1
// @description Enables MathJax on wikispaces for $..$.
// @match      http://mmpii.wikispaces.com/*
// @match      https://mmpii.wikispaces.com/*
// @require    https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js
// @copyright
// ==/UserScript==

window.addEventListener ("load", function() {
    var VERSION = 2.1;

    if (window.top != window.self)  //don't run on frames or iframes
        return;

    window.setTimeout(function () {
        //Revent '{{...}}' formatting
        $('tt').each(function() {
            var that = $(this);
            that.text('{{' +  that.text() + '}}');
            that.contents().unwrap();
        });

        $.getScript('https://n.ethz.ch/student/langl/MathJaxVer.js', function() {
            if (NEWEST > VERSION)
            {
                alert('A new version of the \'MathJax for Wikispaces\' script is available. You will be redirected to the update site');
                window.location.href = 'https://openuserjs.org/scripts/mathe172/MathJax_for_Wikispaces';
            }
            
            console.log('Newest version of userscript: ' + NEWEST);
        });

        $.getScript('https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML', function() {
            MathJax.Hub.Config({
                extensions: ["tex2jax.js"], 
                tex2jax: { skipTags: ["script","noscript","style","textarea"],
                          inlineMath: [["$", "$"], ["\\(", "\\)"]], 
                          displayMath: [["\\[","\\]"]], 
                          processEscapes: true 
                         }, 
                jax: ["input/TeX", "output/HTML-CSS"]
            });
            MathJax.Hub.Startup.onload();

            doMathJax = function () {
                window.setTimeout(doMathJax, 1000);
                if(MathJax !== undefined) MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
            }
            
            doMathJax();
        });
    }, 5000);
}, false);