Skip to content

Instantly share code, notes, and snippets.

@petr-kalinin
Created June 15, 2016 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petr-kalinin/df94e4477c0d9156355243d7d7a9527c to your computer and use it in GitHub Desktop.
Save petr-kalinin/df94e4477c0d9156355243d7d7a9527c to your computer and use it in GitHub Desktop.
Enable TeX support on vk
// ==UserScript==
// @author Petr Kalinin
// @name Support MathJax in vk.com
// @version 0.2
// @date 2012-09-25
// @description Load MathJax code to vk.com pages
// @license MIT (https://opensource.org/licenses/MIT)
// @include http://vk.com/*
// @include http://*vk.com/*
// @include https://vk.com/*
// @include https://*vk.com/*
// ==/UserScript==
/*
UserScript to convert (La)TeX on vk.com pages to images via MathJax
Copyright (C) Petr Kalinin, 2012
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (window.location.href.indexOf('vk.com')>-1)
{
var head = document.getElementsByTagName("head")[0], script;
script = document.createElement("script");
script.type = "text/x-mathjax-config";
script[(window.opera ? "innerHTML" : "text")] =
"MathJax.Hub.Config({\n" +
" tex2jax: { \n" +
" inlineMath: [['\\\\(','\\\\)']],\n" +
" displayMath: [['\\\\[','\\\\]']],\n" +
' skipTags: ["script","noscript","style","textarea","pre","code"]\n' +
" }\n" +
"});"
head.appendChild(script);
script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
head.appendChild(script);
var willRunMathJax = 0;
setInterval( function() { willRunMathJax = 0; } , 2000);
function queueTypeset() {
MathJax.Hub.Queue(function () {
willRunMathJax = 0;
});
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
function processDocumentChange() {
if (willRunMathJax== 0) {
willRunMathJax = 1;
setTimeout(queueTypeset, 2000);
}
}
var body = document.getElementsByTagName("body")[0];
// Not sure we need to trigger all these events, by why not?
body.addEventListener('DOMNodeInserted', processDocumentChange, false );
body.addEventListener('DOMNodeInsertedIntoDocument', processDocumentChange, false );
body.addEventListener('DOMCharacterDataModified', processDocumentChange, false );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment