This commit is contained in:
Timothy J. Baek 2024-06-23 23:10:26 -07:00
parent bc73cb1390
commit f33ca4c9a5
2 changed files with 35 additions and 27 deletions

View File

@ -127,6 +127,41 @@
} }
onMount(async () => { onMount(async () => {
window.addEventListener('message', async (event) => {
if (event.origin === window.origin) {
// Replace with your iframe's origin
console.log('Message received from iframe:', event.data);
if (event.data.type === 'input:prompt') {
console.log(event.data.text);
const inputElement = document.getElementById('chat-textarea');
if (inputElement) {
prompt = event.data.text;
inputElement.focus();
}
}
if (event.data.type === 'action:submit') {
console.log(event.data.text);
if (prompt !== '') {
await tick();
submitPrompt(prompt);
}
}
if (event.data.type === 'input:prompt:submit') {
console.log(event.data.text);
if (prompt !== '') {
await tick();
submitPrompt(event.data.text);
}
}
}
});
if (!$chatId) { if (!$chatId) {
chatId.subscribe(async (value) => { chatId.subscribe(async (value) => {
if (!value) { if (!value) {

View File

@ -50,33 +50,6 @@
} }
}; };
window.addEventListener('message', (event) => {
if (event.origin === window.origin) {
// Replace with your iframe's origin
console.log('Message received from iframe:', event.data);
if (event.data.type === 'input:prompt') {
console.log(event.data.text);
const inputElement = document.getElementById('chat-textarea');
if (inputElement) {
inputElement.value = event.data.text;
inputElement.focus();
}
}
if (event.data.type === 'action:submit-prompt') {
console.log(event.data.text);
const submitButtonElement = document.getElementById('send-message-button');
if (submitButtonElement) {
submitButtonElement.click();
}
}
}
});
window.addEventListener('resize', onResize); window.addEventListener('resize', onResize);
const setWakeLock = async () => { const setWakeLock = async () => {