diff --git a/js/mzta-chatgpt.js b/js/mzta-chatgpt.js index b535e2e2..008a7355 100644 --- a/js/mzta-chatgpt.js +++ b/js/mzta-chatgpt.js @@ -107,15 +107,16 @@ function addCustomDiv(prompt_action,tabId) { break; case 1: // do reply pulsante.innerHTML = browser.i18n.getMessage("chatgpt_win_get_answer"); - pulsante.onclick = async function() { // TODO + pulsante.onclick = async function() { const response = await chatgpt_getFromDOM('last'); + browser.runtime.sendMessage({command: "chatgpt_replyMessage", text: response, tabId: tabId}); //console.log(response); browser.runtime.sendMessage({command: "chatgpt_close"}); }; break; case 2: // replace text pulsante.innerHTML = browser.i18n.getMessage("chatgpt_win_get_answer"); - pulsante.onclick = async function() { // TODO + pulsante.onclick = async function() { const response = await chatgpt_getFromDOM('last'); //console.log('replace text: '+tabId) browser.runtime.sendMessage({command: "chatgpt_replaceSelectedText", text: response, tabId: tabId}); diff --git a/mzta-background.js b/mzta-background.js index 85ed4f96..733065e1 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -44,6 +44,14 @@ messenger.runtime.onMessage.addListener((message, sender, sendResponse) => { //console.log('chatgpt_replaceSelectedText: [' + message.tabId +'] ' + message.text) browser.tabs.sendMessage(message.tabId, { command: "replaceSelectedText", text: message.text }); return true; + case 'chatgpt_replyMessage': + browser.messageDisplay.getDisplayedMessage(message.tabId).then((mailMessage) => { + browser.compose.beginReply(mailMessage.id, { + type: "reply", + body: message.text + }) + }); + break; default: break; }