diff --git a/api_webchat/messagesArea.js b/api_webchat/messagesArea.js index 7f3bf1d6..4e00c8b5 100644 --- a/api_webchat/messagesArea.js +++ b/api_webchat/messagesArea.js @@ -235,14 +235,15 @@ class MessagesArea extends HTMLElement { switch(promptData.action) { case "1": // do reply // console.log("[ThunderAI] (do reply) fullTextHTMLAtAssignment: " + fullTextHTMLAtAssignment); - browser.runtime.sendMessage({command: "chatgpt_replyMessage", text: fullTextHTMLAtAssignment, tabId: promptData.tabId, mailMessageId: promptData.mailMessageId}); - browser.runtime.sendMessage({command: "chatgpt_close"}); + browser.runtime.sendMessage({command: "chatgpt_replyMessage", text: fullTextHTMLAtAssignment, tabId: promptData.tabId, mailMessageId: promptData.mailMessageId}).then(() => { + browser.runtime.sendMessage({command: "chatgpt_close"}); + }); break; case "2": // replace text // console.log("[ThunderAI] (replace text) fullTextHTMLAtAssignment: " + fullTextHTMLAtAssignment); - browser.runtime.sendMessage({command: "chatgpt_replaceSelectedText", text: fullTextHTMLAtAssignment, tabId: promptData.tabId, mailMessageId: promptData.mailMessageId}); - //console.log(response); - browser.runtime.sendMessage({command: "chatgpt_close"}); + browser.runtime.sendMessage({command: "chatgpt_replaceSelectedText", text: fullTextHTMLAtAssignment, tabId: promptData.tabId, mailMessageId: promptData.mailMessageId}).then(() => { + browser.runtime.sendMessage({command: "chatgpt_close"}); + }); break; } }); diff --git a/js/mzta-chatgpt.js b/js/mzta-chatgpt.js index e4f45db5..56d63df7 100644 --- a/js/mzta-chatgpt.js +++ b/js/mzta-chatgpt.js @@ -167,9 +167,9 @@ function addCustomDiv(prompt_action,tabId,mailMessageId) { btn_ok.textContent = browser.i18n.getMessage("chatgpt_win_get_answer"); btn_ok.onclick = async function() { const response = getSelectedHtml(); - browser.runtime.sendMessage({command: "chatgpt_replyMessage", text: response, tabId: tabId, mailMessageId: mailMessageId}); - //console.log(response); - browser.runtime.sendMessage({command: "chatgpt_close"}); + browser.runtime.sendMessage({command: "chatgpt_replyMessage", text: response, tabId: tabId, mailMessageId: mailMessageId}).then(() => { + browser.runtime.sendMessage({command: "chatgpt_close"}); + }); }; break; case "2": // replace text @@ -178,9 +178,9 @@ function addCustomDiv(prompt_action,tabId,mailMessageId) { btn_ok.onclick = async function() { const response = getSelectedHtml(); //console.log('replace text: '+tabId) - browser.runtime.sendMessage({command: "chatgpt_replaceSelectedText", text: response, tabId: tabId, mailMessageId: mailMessageId}); - //console.log(response); - browser.runtime.sendMessage({command: "chatgpt_close"}); + browser.runtime.sendMessage({command: "chatgpt_replaceSelectedText", text: response, tabId: tabId, mailMessageId: mailMessageId}).then(() => { + browser.runtime.sendMessage({command: "chatgpt_close"}); + }); }; break; }