improved linebreaks. see #482
This commit is contained in:
parent
74f5369a31
commit
49b9ab1b6c
1 changed files with 12 additions and 16 deletions
|
|
@ -32,23 +32,23 @@ let isDragging = false;
|
||||||
|
|
||||||
async function chatgpt_sendMsg(msg, method ='') { // return -1 send button not found, -2 textarea not found
|
async function chatgpt_sendMsg(msg, method ='') { // return -1 send button not found, -2 textarea not found
|
||||||
let textArea = document.getElementById('prompt-textarea')
|
let textArea = document.getElementById('prompt-textarea')
|
||||||
let old_textArea = false;
|
|
||||||
if(!textArea){
|
|
||||||
textArea = document.querySelector('form textarea');
|
|
||||||
old_textArea = true;
|
|
||||||
}
|
|
||||||
//check if the textarea has been found
|
//check if the textarea has been found
|
||||||
if(!textArea) {
|
if(!textArea) {
|
||||||
console.error("[ThunderAI] Textarea not found!");
|
console.error("[ThunderAI] Textarea not found!");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
if(old_textArea){
|
// from sept 2024
|
||||||
textArea.value = msg;
|
// Remove existing content
|
||||||
textArea.dispatchEvent(new Event('input', { bubbles: true })); // enable send button
|
while (textArea.firstChild) {
|
||||||
} else { // from sept 2024
|
textArea.removeChild(textArea.firstChild);
|
||||||
textArea.innerText = msg;
|
|
||||||
textArea.dispatchEvent(new Event('input', { bubbles: true }));
|
|
||||||
}
|
}
|
||||||
|
// Parse msg as HTML and append its nodes
|
||||||
|
const parser = new DOMParser();
|
||||||
|
const doc = parser.parseFromString(msg, 'text/html');
|
||||||
|
Array.from(doc.body.childNodes).forEach(node => {
|
||||||
|
textArea.appendChild(node.cloneNode(true));
|
||||||
|
});
|
||||||
|
textArea.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
//wait for the button to change from the audio button to the send button (from nov-2024)
|
//wait for the button to change from the audio button to the send button (from nov-2024)
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
let sendButton = document.querySelector('[data-testid="send-button"]') // pre-GPT-4o
|
let sendButton = document.querySelector('[data-testid="send-button"]') // pre-GPT-4o
|
||||||
|
|
@ -502,7 +502,7 @@ async function doProceed(message, customText = ''){
|
||||||
if(_gpt_model != ''){
|
if(_gpt_model != ''){
|
||||||
await checkGPTModel(_gpt_model);
|
await checkGPTModel(_gpt_model);
|
||||||
}
|
}
|
||||||
let final_prompt = replaceBrWithNewline(message.prompt);
|
let final_prompt = message.prompt;
|
||||||
// console.log(">>>>>>>>>>>> doProceed customText: " + customText);
|
// console.log(">>>>>>>>>>>> doProceed customText: " + customText);
|
||||||
// console.log(">>>>>>>>>>>> doProceed final_prompt: " + final_prompt);
|
// console.log(">>>>>>>>>>>> doProceed final_prompt: " + final_prompt);
|
||||||
// console.log(">>>>>>>>>>>> doProceed mztaPhDefVal: " + JSON.stringify(mztaPhDefVal));
|
// console.log(">>>>>>>>>>>> doProceed mztaPhDefVal: " + JSON.stringify(mztaPhDefVal));
|
||||||
|
|
@ -774,10 +774,6 @@ function run(checkTab = null) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceBrWithNewline(input) {
|
|
||||||
return input.replace(/<br\\s*\\/?>/gi, '\\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
// In the content script
|
// In the content script
|
||||||
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||||
//console.log(">>>>>>>>>>>>> content.js onMessage: " + JSON.stringify(message));
|
//console.log(">>>>>>>>>>>>> content.js onMessage: " + JSON.stringify(message));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue