From ab3552ea67476e61cd95cc8ec4d75344e9850fa7 Mon Sep 17 00:00:00 2001 From: mic Date: Wed, 17 Apr 2024 22:55:39 +0200 Subject: [PATCH] Fixed the new chat layout with the change model button that adds a number at the end of the text. Fixes #29 --- js/mzta-chatgpt.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/js/mzta-chatgpt.js b/js/mzta-chatgpt.js index 0208a393..20aa2c7c 100644 --- a/js/mzta-chatgpt.js +++ b/js/mzta-chatgpt.js @@ -56,7 +56,18 @@ async function chatgpt_getFromDOM(pos) { if (responseDivs.length) { if (/last|final/.test(strPos)){ // get last response responseDivs[responseDivs.length - 1].innerHTML = responseDivs[responseDivs.length - 1].innerHTML.replace(/<\\/p>/g, '

\\n\\n').replace(//g, '
\\n'); + // Removing the new buttons that let the user change model and insert a number (4 or 3.5 at the end of the text) + let parser = new DOMParser(); + let doc = parser.parseFromString(responseDivs[responseDivs.length - 1].innerHTML, 'text/html'); + // Select the div with class 'empty:hidden' + let divToRemove = doc.querySelector('div.empty\\\\:hidden'); + if (divToRemove) { + divToRemove.remove(); + } + // Extract the new HTML string + responseDivs[responseDivs.length - 1].innerHTML = doc.body.innerHTML; response = responseDivs[responseDivs.length - 1].textContent; + //console.log('chatgpt_getFromDOM: '+response); //console.log('chatgpt_getFromDOM: [HTML] ' + responseDivs[responseDivs.length - 1].innerHTML.replace(/]*>/gi, '').replace(/<\\/div>/gi, '').replace(/]*>/gi, '').replace(/<\\/svg>/gi, '').replace(/]*>/gi, '').replace(/<\\/path>/gi, '').replace(/]*>/gi, '').replace(/<\\/text>/gi, '').replace(/]*>/gi, '').replace(/<\\/span>/gi, '').replace(/]*>/gi, '').replace(/<\\/button>/gi, '')); } else { // get nth response const nthOfResponse = (