如何使用GreaseMonkey脚本在Github中运行Mathjax(问题页面,降价,维基,...)?

时间:2017-04-05 08:20:12

标签: javascript github greasemonkey mathjax

我使用the answer in this question稍微调整了一下代码,因为它已经过时了(特别是用cdn.mathjax.org提供的代码替换了url脚本原点):

// ==UserScript==
// @name           Running MathJax in Github
// @namespace      https://www.mathjax.org/
// @description    Runs MathJax on any page in Github.com
// @include        http://github.com/*
// @include        https://github.com/*
// @include        https://raw.githubusercontent.com/*
// ==/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://cdn.mathjax.org/mathjax/latest/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);

})();

然而,在问题页面或降价或维基中使用Github时仍然无效。

0 个答案:

没有答案