-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
41 lines (35 loc) · 1.17 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
function extractProductInfo() {
const productName =
document.querySelector(".product-name")?.innerText || "Unknown Product";
const productBrand =
document.querySelector(".brand-name")?.innerText || "Unknown Brand";
const productDescription =
document.querySelector(".description")?.innerText || "";
return { productName, productBrand, productDescription };
}
function analyzeSustainability(productInfo) {
const sustainableKeywords = [
"organic",
"recycled",
"sustainable",
"eco-friendly",
];
let score = 0;
sustainableKeywords.forEach((keyword) => {
if (productInfo.productDescription.toLowerCase().includes(keyword)) {
score += 25;
}
});
if (productInfo.productBrand.toLowerCase() === "known sustainable brand") {
score += 25;
}
return score >= 50 ? "Sustainable" : "Not Sustainable";
}
// sends sustainability data back to popup
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "checkSustainability") {
const productInfo = extractProductInfo();
const sustainabilityStatus = analyzeSustainability(productInfo);
sendResponse(sustainabilityStatus);
}
});