-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
25 lines (22 loc) · 883 Bytes
/
background.js
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
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "sendEmail") {
const url = "https://cmailerapi.codingteam.tech/send-email";
const payload = JSON.stringify(request.data);
const xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
sendResponse({ success: true });
} else {
const responseObj = JSON.parse(xhr.responseText);
const error_message = responseObj.message || "Erreur lors de l'envoi de l'e-mail.";
sendResponse({ success: false, message: error_message });
}
}
};
xhr.send(payload);
return true; // Indique que sendResponse sera appelé de manière asynchrone
}
});