Guest User

LaTeXhk.js

a guest
Oct 25th, 2016
192
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @autor       Anonymous
  3. // @name        LaTeXhk
  4. // @namespace   LaTeXhk
  5. // @include     /^https?:\/\/2ch\.(hk|pm|re|tf|wj)/(sci|test|math)/
  6. // @version     2.1.2
  7. // @grant       GM_getValue
  8. // @grant       GM_setValue
  9. // @grant       GM_xmlhttpRequest
  10. // ==/UserScript==
  11.  
  12.  
  13. mathJaxOpt = document.createElement('script');
  14. mathJaxOpt.type = 'text/x-mathjax-config';
  15. mathJaxOpt[(mathJaxOpt.innerText===undefined?"textContent":"innerText")] = 'MathJax.Hub.Config({AsciiMath: { fixphi: true, useMathMLspacing: true, displaystyle: false, decimalsign: "."}, tex2jax: {inlineMath: [[\'$\',\'$\']]}});';
  16. document.getElementsByTagName('head')[0].appendChild(mathJaxOpt);
  17. mathJax = document.createElement('script');
  18. mathJax.type = 'text/javascript';
  19. mathJax.src = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_HTMLorMML"; // only asciiMath AM_HTMLorMML, Only LaTeX and TeX TeX-AMS-MML_HTMLorMML, for all TeX-MML-AM_HTMLorMML
  20. document.getElementsByTagName('head')[0].appendChild(mathJax);
  21. //area footer
  22. previewArea = document.createElement('tr');
  23. previewArea.className = "preview-area";
  24. previewAreaLabelCont = document.createElement('td');
  25. previewAreaLabelCont.className = 'label desktop';
  26. previewAreaLabel = document.createElement('label');
  27. previewAreaLabel.setAttribute('for','preview');
  28. previewAreaLabel.innerHTML = 'Предпросмотр';
  29. previewAreaLabelCont.appendChild(previewAreaLabel);
  30. previewArea.appendChild(previewAreaLabelCont);
  31. preview = document.createElement('td');
  32. preview.className = "preview";
  33. previewArea.appendChild(preview);
  34. var options = document.getElementsByClassName('option-area desktop')[0];
  35.  
  36. //area short window
  37. previewWindow = document.createElement('div');
  38. previewWindow.className = "preview-window";
  39. var optionsWindow = document.getElementsByClassName('qr-mail')[0];
  40.  
  41. function ClickPreviewButton(){
  42.   if (options.parentNode!==previewArea.parentNode){
  43.     options.parentNode.insertBefore(previewArea,options);
  44.   }
  45.   optionsWindow.parentNode.insertBefore(previewWindow,optionsWindow);
  46.   var html =document.getElementsByClassName('symbol-counter')[0].children[1].value;
  47.   html = html.replace(/\n/g, "<br>");
  48.   preview.innerHTML=html;
  49.   previewWindow.innerHTML=html;  
  50.   window.postMessage("latex_update", "*");
  51.   };
  52.  
  53. previewButton = document.createElement('input');
  54. previewButton.id = 'previewButton';
  55. previewButton.className = 'all-platform';
  56. previewButton.type = 'button';
  57. previewButton.value = 'Предпросмотр';
  58. previewButton.name = 'previewButton';
  59. previewButton.onclick = ClickPreviewButton;
  60.  
  61. previewButtonQr = document.createElement('input');
  62. previewButtonQr.id = 'previewButtonQr';
  63. previewButtonQr.className = 'all-platform';
  64. previewButtonQr.type = 'button';
  65. previewButtonQr.value = 'Предпросмотр';
  66. previewButtonQr.name = 'previewButtonQr';
  67. previewButtonQr.onclick = ClickPreviewButton;
  68.  
  69.  
  70.  
  71. document.getElementById("e-mail").style.width = "250px";
  72. document.getElementsByClassName('mail')[0].children[1].appendChild(previewButton);
  73.  
  74. document.getElementById("qr-e-mail").style.width = "300px";
  75. document.getElementsByClassName('qr-mail')[0].appendChild(previewButtonQr);
  76.  
  77.  
  78. var script = document.createElement('script');
  79. script.textContent = '\
  80. var storedUpdatePosts = updatePosts;\
  81. updatePosts = function(callback){\
  82. storedUpdatePosts(callback);\
  83. setTimeout("MathJax.Hub.Typeset();",500);\
  84. };\
  85. window.addEventListener("message", function(e) {\
  86. if (e.data == "latex_update") {\
  87.   MathJax.Hub.Typeset(); \
  88. }\
  89. }, false);\
  90. ';
  91. script.type = "text/javascript";
  92. document.body.appendChild(script);
RAW Paste Data