MathJax for All

Uses MathJax to properly display LaTeX code, on any site

目前為 2021-05-21 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name MathJax for All
  3. // @version 0.2
  4. // @description Uses MathJax to properly display LaTeX code, on any site
  5. // @namespace 1993.uk
  6. // @match https://mail.google.com/*
  7. // @match file:///*
  8. // ==/UserScript==
  9. if (window.MathJax === undefined) {
  10. var mjscr = document.createElement("script");
  11. mjscr.type = "text/javascript";
  12. mjscr.src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js";
  13. mjscr.text = 'MathJax.Hub.Config({extensions:["tex2jax.js"],'+"tex2jax:{inlineMath:[['$','$']]"
  14. +',skipTags:["script","noscript","pre","code"]},jax:["input/TeX","output/CommonHTML"]});MathJax.Hub.Startup.onload();';
  15. document.getElementsByTagName("head")[0].appendChild(mjscr);
  16.  
  17. (new MutationObserver(function(mutationsList, observer) {
  18. let el = [];
  19. for (const mutation of mutationsList) {
  20. const node = mutation.addedNodes.item(0);
  21. if (node === null || node.nodeType !== 1 || node.className == "MathJax_Preview" || node.id.substring(0,7) == "MathJax" || node.className.substring(0,4) == "mjx-") break;
  22. if (node.offsetParent !== null && node.innerText != "") el.push(node);
  23. }
  24. if (el.length != 0) MathJax.Hub.Queue(["Typeset", MathJax.Hub,el,{}]);
  25. })).observe(document,{subtree: true, childList: true});
  26. }