From 4a789bac1115e449ae16d7a1ef1cfddd8884708e Mon Sep 17 00:00:00 2001 From: mic Date: Tue, 30 Apr 2024 22:47:14 +0200 Subject: [PATCH] inserting text for the reply from the background script. see #30 #34 --- mzta-background.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mzta-background.js b/mzta-background.js index c0579db2..96ba2690 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -19,7 +19,7 @@ import { mzta_script } from './js/mzta-chatgpt.js'; import { prefs_default } from './options/mzta-options-default.js'; import { mzta_Menus } from './js/mzta-menus.js'; -import { getCurrentIdentity } from './js/mzta-utils.js'; +import { getCurrentIdentity, replaceBody } from './js/mzta-utils.js'; var createdWindowID = null; @@ -62,17 +62,17 @@ messenger.runtime.onMessage.addListener(async (message, sender, sendResponse) => break; case 'chatgpt_replaceSelectedText': //console.log('chatgpt_replaceSelectedText: [' + message.tabId +'] ' + message.text) - browser.tabs.sendMessage(message.tabId, { command: "replaceSelectedText", text: message.text }); + browser.tabs.sendMessage(message.tabId, { command: "replaceSelectedText", text: message.text, tabId: message.tabId }); return true; case 'chatgpt_replyMessage': const paragraphsHtmlString = message.text; let prefs = await browser.storage.sync.get({reply_type: 'reply_all'}); - console.log('reply_type: ' + prefs.reply_type); + //console.log('reply_type: ' + prefs.reply_type); let replyType = 'replyToAll'; if(prefs.reply_type === 'reply_sender'){ replyType = 'replyToSender'; } - console.log('replyType: ' + replyType); + //console.log('replyType: ' + replyType); browser.messageDisplay.getDisplayedMessage(message.tabId).then(async (mailMessage) => { let reply_tab = await browser.compose.beginReply(mailMessage.id, replyType, { type: "reply", @@ -100,7 +100,8 @@ messenger.runtime.onMessage.addListener(async (message, sender, sendResponse) => } }); // we need to wait for the compose windows to load the content script - setTimeout(() => browser.tabs.sendMessage(reply_tab.id, { command: "insertText", text: paragraphsHtmlString }), 500); + //setTimeout(() => browser.tabs.sendMessage(reply_tab.id, { command: "insertText", text: paragraphsHtmlString, tabId: reply_tab.id }), 500); + setTimeout(() => replaceBody(reply_tab.id, paragraphsHtmlString), 500); return true; }); break;