-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
51 lines (44 loc) · 1.32 KB
/
background.js
File metadata and controls
51 lines (44 loc) · 1.32 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const apiKey = "QY21KK1KOQ8Z098CS63OCMZLFHLL1ADY";
/* chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'detectAI') {
const text = request.text;
fetch('https://api.sapling.ai/api/v1/aidetect', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`,
},
body: JSON.stringify({ text }),
})
.then((response) => response.json())
.then((result) => {
sendResponse({ result });
})
.catch((error) => {
sendResponse({ error: error.message });
});
return true;
}
}); */
chrome.runtime.onMessage.addListener(async (data) => {
try {
if (data.event == "detectAI" && data.prefs.text.trim("") != "") {
const input = {
key: apiKey,
text: data.prefs.text,
};
const res = await fetch("https://api.sapling.ai/api/v1/aidetect", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(input),
});
const finres = await res.json();
console.log("Response: " + JSON.stringify(finres));
chrome.storage.local.set(finres);
}
} catch (e) {
console.log(e.message);
}
});