fsavje/math-with-slack

Make proper version for Linux and Windows

fsavje opened this issue · 6 comments

Make proper version for Linux and Windows

When I add

// *** Code injected for MathJax support
    // See: https://github.com/fsavje/math-with-slack

    var mathjax_inject_script = `
      var mathjax_config = document.createElement("script");
      mathjax_config.type = "text/x-mathjax-config";
      mathjax_config.text = \`
        MathJax.Hub.Config({
          messageStyle: "none",
          extensions: ["tex2jax.js"],
          jax: ["input/TeX", "output/HTML-CSS"],
          tex2jax: {
            skipTags: ["script","noscript","style","textarea","pre","code"],
            inlineMath: [ ['\$','\$'] ],
            displayMath: [ ['\$\$','\$\$'] ],
            processEscapes: true
          },
          TeX: {
            extensions: ["noErrors.js", "noUndefined.js"]
          }
        });
        \`;
      var mathjax_script = document.createElement("script");
      mathjax_script.type = "text/javascript";
      mathjax_script.src = "https://cdn.mathjax.org/mathjax/latest/MathJax.js";
      document.getElementsByTagName("head")[0].appendChild(mathjax_config);
      document.getElementsByTagName("head")[0].appendChild(mathjax_script);

      var render = function (records, observer) {
          MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
      };
      var target = document.querySelector('#msgs_div');
      var observer = new MutationObserver(render);
      var config = { attributes: false, childList: true, characterData: true, subtree: true };
      observer.observe(target, config);
    `;

    window.webviews = document.querySelectorAll(".TeamView webview");
    setTimeout(function() {
      for(var i = 0; i < webviews.length; i++) {
        webviews[i].executeJavaScript(mathjax_inject_script);
      }
    }, 10000);

    // *** End injected MathJax

below startup(); call in index.js (line 41 in my case) it works just fine under Windows. Only the bash script wouldn't work.

(Note, that I only did change the bash escapes of the grave accent above compared to what one finds in the sh file)

Thank you @crstnbr. I suspected that would be the case. Excellent that you could confirm that for me. I'll try to draft up a batch script as soon as possible. Thanks again!

Youre welcome. Thanks for coming up with this in the first place.

Btw, the index.js file was located here:

C:\Users\<USERNAME>\AppData\Local\slack\app-2.5.1\resources\app.asar.unpacked\src\static\index.js

Hey @crstnbr I've added a windows version. If you want, it would be great if you could try it out. Just follow the instructions here to install it.

I've added some safety checks so that it doesn't overwrites the wrong file. If you've edited index.js by hand, you'll probably need to restore it to the original version for the script to work. If you didn't take a backup, here's the original version: index.js.zip

Thanks for helping out!

Worked for me!

Excellent, thanks!