-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
36 lines (30 loc) · 1.11 KB
/
background.js
File metadata and controls
36 lines (30 loc) · 1.11 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
browser.composeAction.onClicked.addListener(async (tab) => {
try {
const details = await browser.compose.getComposeDetails(tab.id);
const plainBody = details.plainTextBody || details.body || '';
const email = details.to && details.to.length > 0 ? details.to[0] : '';
if (!email || !plainBody.trim()) {
console.log('Lion Stack AI: missing recipient or body');
return;
}
const response = await fetch('https://travelmanager.hu/api/mailspring', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, message: plainBody })
});
if (!response.ok) {
const text = await response.text();
console.error('Lion Stack AI HTTP error', response.status, text);
return;
}
const data = await response.json();
const text = data.reply || '';
const html = text
.replace(/\\n/g, '\n')
.replace(/\n{2,}/g, '</p><p>')
.replace(/\n/g, '<br>');
await browser.compose.setComposeDetails(tab.id, { body: html });
} catch (err) {
console.error('Lion Stack AI request failed', err);
}
});