// ==UserScript==
// @name Poe Latex Renderer
// @namespace http://tampermonkey.net/
// @version 0.9
// @description Prelimary Version, handwork needed
// @author You
// @match https://poe.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=poe.com
// @grant none
// @downloadURL https://update.greasyfork.icu/scripts/461973/Poe%20Latex%20Renderer.user.js
// @updateURL https://update.greasyfork.icu/scripts/461973/Poe%20Latex%20Renderer.meta.js
// ==/UserScript==
(function() {
'use strict';
const renderLatex = function() {
MathJax.typeset();
}
function endOfChat() {
const isEndOfChat = function () {
if (document.querySelector("[class*='ChatMessageFeedbackButtons_feedbackButtonsContainer']") != void 0) return true;
return false;
}
return new Promise((resolve, reject) => {
const resolver = () => {
if (isEndOfChat()) {
return resolve();
}
window.setTimeout(resolver, 500);
}
setTimeout(resolver, 1000);
})
}
function createBtnAndInit() {
const btnsCSS = `
display: flex;
align-items: center;
justify-content: center;
height: 50px;
cursor: pointer;
`
renderLatex();
document.querySelector("[class*='ChatMessageInputView_sendButtonWrapper']").style.right = '55px';
const _sc_renderBtnContainer = document.createElement("div");
_sc_renderBtnContainer.style.cssText = btnsCSS;
_sc_renderBtnContainer.innerHTML = '';
_sc_renderBtnContainer.addEventListener('click', () => { renderLatex(); })
const _sc_writeBtnContainer = document.createElement("div");
_sc_writeBtnContainer.style.cssText = btnsCSS;
_sc_writeBtnContainer.innerHTML = ''
_sc_writeBtnContainer.addEventListener('click', async ()=>{
const txtArea = document.querySelector("[class*='ChatMessageInputView_textInput__Aervw']");
txtArea.value = `Please write your equations in LaTex, surround all latex blocks by '$$', and also surround all inline latex by '$'. \n\n ${txtArea.value}`;
document.querySelector("[class*='ChatMessageInputView_sendButton_']").click();
await endOfChat();
renderLatex();
})
document.querySelector("[class*='ChatMessageInputView_inputWrapper']").append(_sc_writeBtnContainer)
document.querySelector("[class*='ChatMessageInputView_inputWrapper']").append(_sc_renderBtnContainer)
}
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']],
displayMath : [['$$', '$$', ['\\[', '\\]']]]
},
svg: {
fontCache: 'global'
},
startup: {
typeset: false
},
options: {
skipHtmlTags: [ // HTML tags that won't be searched for math
'script', 'noscript', 'style', 'textarea', 'annotation', 'annotation-xml'],
includeHtmlTags: { // HTML tags that can appear within math
br: '\n',
wbr: '',
'#comment': ''
},
ignoreHtmlClass: 'tex2jax_ignore',
// class that marks tags not to search
processHtmlClass: 'tex2jax_process',
// class that marks tags that should be searched
compileError: function(doc, math, err) {
doc.compileError(math, err)
},
typesetError: function(doc, math, err) {
doc.typesetError(math, err)
},
}
};
(function () {
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js';
script.async = true;
document.head.appendChild(script);
})();
(()=>{
const _sc_style = document.createElement("style");
//.MathJax { font-size: 1.3em !important; }
_sc_style.innerHTML = `
svg {
height: initial;
}
section[class*='PageWithSidebarLayout_mainSection'] {
width: initial;
max-width: initial;
}
`
document.head.appendChild(_sc_style);
})();
setTimeout(createBtnAndInit, 2000);
// Your code here...
})();