-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
26 lines (25 loc) · 844 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
26
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "analyzeText") {
request.data.forEach((text) => {
fetch("https://perspectiveapi.com/analyze", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
},
body: JSON.stringify({
comment: { text },
languages: ["en"],
requestedAttributes: { TOXICITY: {} }
})
})
.then((response) => response.json())
.then((data) => {
if (data.attributeScores.TOXICITY.summaryScore.value >= 0.7) {
console.log(`Abusive content found: "${text}"`);
// Code to flag or blur abusive content
}
});
});
}
});