// ==UserScript==
// @name           MathJax in Wikipedia
// @namespace      http://www.mathjax.org/
// @description    Insert MathJax into Wikipedia pages
// @include        http://en.wikipedia.org/wiki/*
// ==/UserScript==

if ((window.unsafeWindow == null ? window : unsafeWindow).MathJax == null) {
  //
  //  Replace the images with MathJax scripts of type math/tex
  //
  var images = document.getElementsByTagName('img'), count = 0;
  for (var i = images.length - 1; i >= 0; i--) {
    var img = images[i];
    if (img.className === "tex") {
      var script = document.createElement("script"); script.type = "math/tex";
      if (window.opera) {script.innerHTML = img.alt} else {script.text = img.alt}
      img.parentNode.replaceChild(script,img); count++;
    }
  }
  if (count) {
    //
    //  Load MathJax and have it process the page
    //
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/latest.js?config=TeX-AMS-MML_CHTML-full";
    document.getElementsByTagName("head")[0].appendChild(script);
  }
}

@@ -74,16 +74,17 @@
     http
+s
 ://www.m
@@ -177,13 +177,13 @@
 http
+s
 ://
-en
+*
 .wik
@@ -224,97 +224,12 @@
 ==%0A%0A
-if ((window.unsafeWindow == null ? window : unsafeWindow).MathJax == null) %7B%0A  //%0A  //  R
+// r
 epla
@@ -284,24 +284,68 @@
 tex%0A
-  //%0A  
+if (window.MathJax) throw %22MathJax already loaded!%22;%0A
 var im
-age
+g
 s = 
@@ -357,161 +357,126 @@
 ent.
-getElementsByTagName('img'), count = 0;%0A  for (var i = images.length - 1; i %3E= 0; i--) %7B%0A    var img = images%5Bi%5D;%0A    if (img.className === %22tex%22) %7B%0A    
+querySelectorAll('img.mwe-math-fallback-image-inline')%0Aif (!imgs.length) throw %22no matches!%22;%0Aimgs.forEach((img) =%3E %7B%0A
   va
@@ -519,16 +519,18 @@
 cript%22);
+%0A 
  script.
@@ -540,17 +540,17 @@
 e = 
-%22
+'
 math/tex
 %22;%0A 
@@ -549,21 +549,20 @@
 /tex
-%22
+'
 ;%0A  
- 
-   if (
+script%5B
 wind
@@ -573,56 +573,32 @@
 pera
-) %7Bscript.innerHTML = img.alt%7D else %7Bscript.
+ ? 'innerHTML' : '
 text
+'%5D
  = i
@@ -607,14 +607,10 @@
 .alt
-%7D%0A    
+;%0A
   im
@@ -646,62 +646,20 @@
 ipt,
+ 
 img);
- count++;%0A    %7D%0A  %7D%0A  if (count) %7B%0A    //%0A    // 
+%0A%7D)%0A//
  Loa
@@ -701,19 +701,8 @@
 age%0A
-    //%0A    
 var 
@@ -737,23 +737,19 @@
 ent(
-%22
+'
 script
-%22
+'
 );%0A
-    
 scri
@@ -758,17 +758,17 @@
 .type = 
-%22
+'
 text/jav
@@ -774,23 +774,19 @@
 vascript
-%22
+'
 ;%0A
-    
 script.s
@@ -790,17 +790,17 @@
 t.src = 
-%22
+'
 https://
@@ -806,35 +806,20 @@
 /cdn
-js.cloudflare.com/ajax/libs
+.mathjax.org
 /mat
@@ -830,17 +830,23 @@
 /2.7
-.4/
+-
 latest
+/MathJax
 .js?
@@ -868,25 +868,25 @@
 MML_
-C
 HTML
+orMML
 -full
-%22
+'
 ;%0A
-    
 docu
@@ -894,39 +894,29 @@
 ent.
-getElementsByTagName(%22head%22)%5B0%5D
+querySelector('head')
 .app
@@ -937,10 +937,4 @@
 t);%0A
-  %7D%0A%7D%0A

update class, match https/non-en, use working cdn