sending the choosen prompt
This commit is contained in:
parent
c57eeb134d
commit
386d49b63d
4 changed files with 24 additions and 2 deletions
|
|
@ -64,3 +64,13 @@ worker.onmessage = function(event) {
|
||||||
console.error('Unknown event type from worker:', type);
|
console.error('Unknown event type from worker:', type);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||||
|
console.log(">>>>>>>>>>>>> controller.js onMessage: " + JSON.stringify(message));
|
||||||
|
if (message.command === "chatgpt_send") {
|
||||||
|
//send the received prompt to the chatgpt api
|
||||||
|
messageInput._setMessageInputValue(message.prompt);
|
||||||
|
messageInput._handleNewChatMessage();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
@ -13,7 +13,6 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Include the JavaScript files at bottom to avoid blocking UI -->
|
<!-- Include the JavaScript files at bottom to avoid blocking UI -->
|
||||||
<!-- <script src="../js/api/openai.js" type="module" defer></script> -->
|
|
||||||
<script src="messageInput.js" type="module" defer></script>
|
<script src="messageInput.js" type="module" defer></script>
|
||||||
<script src="markdown-it.min.js"></script>
|
<script src="markdown-it.min.js"></script>
|
||||||
<script src="messagesArea.js" type="module" defer></script>
|
<script src="messagesArea.js" type="module" defer></script>
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,10 @@ class MessageInput extends HTMLElement {
|
||||||
}
|
}
|
||||||
this.worker.postMessage({ type: 'chatMessage', message: messageContent });
|
this.worker.postMessage({ type: 'chatMessage', message: messageContent });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_setMessageInputValue(msg) {
|
||||||
|
this._messageInputField.value = msg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define('message-input', MessageInput);
|
customElements.define('message-input', MessageInput);
|
||||||
|
|
@ -158,7 +158,7 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
||||||
|
|
||||||
console.log("[ThunderAI] ChatGPT web interface script started...");
|
console.log("[ThunderAI] ChatGPT web interface script started...");
|
||||||
createdWindowID = newWindow.id;
|
createdWindowID = newWindow.id;
|
||||||
const createdTab = newWindow.tabs[0];
|
let createdTab = newWindow.tabs[0];
|
||||||
|
|
||||||
// Wait for tab loaded.
|
// Wait for tab loaded.
|
||||||
await new Promise(resolve => {
|
await new Promise(resolve => {
|
||||||
|
|
@ -206,6 +206,15 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
||||||
width: prefs.chatgpt_win_width,
|
width: prefs.chatgpt_win_width,
|
||||||
height: prefs.chatgpt_win_height
|
height: prefs.chatgpt_win_height
|
||||||
});
|
});
|
||||||
|
|
||||||
|
createdWindowID = newWindow.id;
|
||||||
|
let createdTab = newWindow.tabs[0];
|
||||||
|
|
||||||
|
let mailMessage = await browser.messageDisplay.getDisplayedMessage(curr_tabId);
|
||||||
|
let mailMessageId = -1;
|
||||||
|
if(mailMessage) mailMessageId = mailMessage.id;
|
||||||
|
|
||||||
|
browser.tabs.sendMessage(createdTab.id, { command: "chatgpt_send", prompt: promptText, action: action, tabId: curr_tabId, mailMessageId: mailMessageId});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue