-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
36 lines (29 loc) · 1.02 KB
/
popup.js
File metadata and controls
36 lines (29 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
document.getElementById('submitText').addEventListener('click', async () => {
const inputText = document.getElementById('inputText').value;
const output = document.getElementById('output');
if (!inputText.trim()) {
output.textContent = 'Please enter some text.';
return;
}
output.textContent = 'Processing...';
try {
const response = await fetch('http://localhost:3000/', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ text: inputText })
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || `HTTP error! status: ${response.status}`);
}
output.textContent = data.answer;
} catch (error) {
console.error('Error fetching AI response:', error);
output.textContent = error.message || 'Error fetching AI response';
if (error.message.includes('quota limits')) {
output.textContent += ' Please try again later or contact support.';
}
}
});