Use MathJax on Wikipedia

Inject MathJax script and hide the fallback images

  1. // ==UserScript==
  2. // @name Use MathJax on Wikipedia
  3. // @description Inject MathJax script and hide the fallback images
  4. // @namespace https://greasyfork.org/en/scripts/427681-use-mathjax-on-wikipedia
  5. // @homepage https://greasyfork.org/en/scripts/427681-use-mathjax-on-wikipedia
  6. // @icon https://www.mathjax.org/favicon.ico
  7. // @match https://*.wikipedia.org/*
  8. // @version 1.0
  9. // @author SriSyadasti
  10. // @grant none
  11. // @license GPL
  12. // ==/UserScript==
  13.  
  14. // This script is for Chrome only.
  15. // For Firefox use this addon: https://addons.mozilla.org/en-US/firefox/addon/native-mathml/
  16.  
  17. // Style copied from: https://github.com/fred-wang/webextension-native-mathml/blob/master/content-scripts/mediawiki.css
  18.  
  19. var sty = document.createElement("style");
  20. sty.textContent = `.mwe-math-mathml-a11y {
  21. clip: auto !important;
  22. overflow: visible !important;
  23. position: static !important;
  24. width: auto !important;
  25. height: auto !important;
  26. opacity: 1 !important;
  27. display: inherit !important;
  28. }
  29. .mwe-math-mathml-inline ~ .lazy-image-placeholder,
  30. .mwe-math-mathml-display ~ .lazy-image-placeholder,
  31. .mwe-math-mathml-inline + .mwe-math-fallback-image-inline,
  32. .mwe-math-mathml-display + .mwe-math-fallback-image-display {
  33. display: none !important;
  34. }`
  35. document.head.appendChild(sty);
  36.  
  37. var scr = document.createElement("script");
  38. scr.id = "MathJax-script";
  39. scr.async = true;
  40. scr.src = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js";
  41. document.head.appendChild(scr);