From 31d3804ad1175596c17125babaebdd5390dcee11 Mon Sep 17 00:00:00 2001
From: mic
Date: Wed, 14 Aug 2024 23:02:49 +0200
Subject: [PATCH] disabling button when replying if nothing is selected. added
a message. see #104
---
_locales/en/messages.json | 2 +-
js/mzta-chatgpt.js | 119 ++++++++++++++++----------------------
2 files changed, 51 insertions(+), 70 deletions(-)
diff --git a/_locales/en/messages.json b/_locales/en/messages.json
index 875b55df..2bfbac4e 100644
--- a/_locales/en/messages.json
+++ b/_locales/en/messages.json
@@ -204,7 +204,7 @@
"description": ""
},
"chatgpt_win_job_completed": {
- "message": "Completed!",
+ "message": "Completed! Select the text you want to use and click the button.",
"description": ""
},
"chatgpt_win_get_answer": {
diff --git a/js/mzta-chatgpt.js b/js/mzta-chatgpt.js
index 6a19bd7f..0e9731bb 100644
--- a/js/mzta-chatgpt.js
+++ b/js/mzta-chatgpt.js
@@ -23,6 +23,7 @@
export const mzta_script = `
let force_go = false;
let current_message = null;
+let selectionChangeTimeout = null;
async function chatgpt_sendMsg(msg, method ='') { // return -1 send button not found, -2 textarea not found
const textArea = document.querySelector('form textarea'),
@@ -62,73 +63,6 @@ function chatgpt_getRegenerateButton() {
}
}
-async function chatgpt_getFromDOM(pos) {
- const responseDivs = document.querySelectorAll('div[data-testid*="conversation-turn"]:nth-child(odd)'),
- strPos = pos.toString().toLowerCase();
- //console.log(">>>>>>>>>>>>> responseDivs.length: "+ responseDivs.length);
- let response = '';
- 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');
- if(!mztaKeepFormatting) { // Return only TEXT
- // Select the div with class 'empty:hidden'
- let correct_div = responseDivs[responseDivs.length - 1].querySelector('div[data-message-author-role="assistant"]');
- response = correct_div.textContent;
- //console.log(">>>>>>>>>> response: " + response);
- response = response.replace(/^ChatGPT(?:ChatGPT)?/, ''); // strip sender name
- response = response.trim().replace(/^"|"$/g, ''); // strip quotation marks
- response = "