// ==UserScript==
// @name Poe Latex Renderer
// @namespace http://tampermonkey.net/
// @version 1.0
// @author You
// @description Render Latex in poe.com
// @match https://poe.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=poe.com
// @grant none
// @license GNU GPLv3
// @downloadURL https://update.greasyfork.icu/scripts/473447/Poe%20Latex%20Renderer.user.js
// @updateURL https://update.greasyfork.icu/scripts/473447/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(".ChatMessageInputContainer_inputContainer__SQvPA").style.right = '55px';
const _sc_renderBtnContainer = document.createElement("div");
const container = document.querySelector(".ChatMessageInputContainer_inputContainer__SQvPA");
if (container.childElementCount >=4){
return;
}
_sc_renderBtnContainer.classList.add("Button_buttonBase__0QP_m", "Button_flat__1hj0f");
_sc_renderBtnContainer.innerHTML = '';
_sc_renderBtnContainer.addEventListener('click', () => { renderLatex(); });
const _sc_writeBtnContainer = document.createElement("div");
_sc_writeBtnContainer.classList.add("Button_buttonBase__0QP_m", "Button_flat__1hj0f");
_sc_writeBtnContainer.innerHTML = ''
_sc_writeBtnContainer.addEventListener('click', async () => {
const txtArea = document.querySelector(".GrowingTextArea_textArea__eadlu");
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(".ChatMessageSendButton_sendButton__OMyK1").click();
await endOfChat();
renderLatex();
})
const lastChild = container.lastChild;
container.insertBefore(_sc_renderBtnContainer, lastChild);
container.insertBefore(_sc_writeBtnContainer, lastChild);
}
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);
})();
setInterval(() => {
createBtnAndInit();
}, 2000);
// Your code here...
})();