-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent.js
28 lines (25 loc) · 967 Bytes
/
content.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
26
27
28
(async function () {
// Extract the body content of the current page
const bodyText = document.body.innerText;
const currentUrl = window.location.href;
// Define the API endpoint
const apiUrl = "https://flagger-ai.vercel.app/api/cache";
try {
// Send the body content to the API
const response = await fetch(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ bodyText, currentUrl }),
});
if (response.status === 200) {
// Redirect the user to your website on success
window.open(`https://flagger-ai.vercel.app/checker/${encodeURIComponent(currentUrl)}`, "_blank");
} else {
console.error("Failed to send data to the API:", response.statusText);
}
} catch (error) {
console.error("Error sending data to the API:", error);
}
})();