Skip to content

Instantly share code, notes, and snippets.

@ncordon
Last active August 31, 2017 17:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncordon/090a6c208e61a1059357d6e8fba03087 to your computer and use it in GitHub Desktop.
Save ncordon/090a6c208e61a1059357d6e8fba03087 to your computer and use it in GitHub Desktop.
GreaseMonkey extension to render Latex only in window of sent messages
// ==UserScript==
// @name TeX for Telegram
// @namespace https://ncordon.github.io/
// @description Allows LaTeX messages in Telegram Desktop
// @version 1
// @include https://web.telegram.org/*
// @grant none
// @license WTFPL
// ==/UserScript==
(function(){
var toRender = document.getElementsByClassName("im_history_scrollable_wrap nano-content")
if(window.MathJax===undefined){
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML";
var config = 'MathJax.Hub.Config({' + 'extensions: ["tex2jax.js"],' +
'tex2jax: { inlineMath: [["$","$"]],' +
'displayMath: [["$$","$$"]], processEscapes: true },' +
'jax: ["input/TeX","output/HTML-CSS"]' + '});' +
'MathJax.Hub.Startup.onload();';
if (window.opera) {
script.innerHTML = config
}
else {
script.text = config
}
document.getElementsByTagName("head")[0].appendChild(script);
(doTexTelegram=function(){
window.setTimeout(doTexTelegram,1000);
MathJax.Hub.Queue(["Typeset", MathJax.Hub, toRender]);
})();
}
else{
MathJax.Hub.Queue(["Typeset", MathJax.Hub, toRender]);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment