-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent.js
26 lines (23 loc) · 914 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
console.log("Content script loaded");
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
console.log("Message received in content script:", request);
if (request.action === "getAddress") {
const scripts = document.querySelectorAll('script[type="application/ld+json"]');
let address = null;
for (let script of scripts) {
try {
const data = JSON.parse(script.textContent);
if (data["@type"] === "Product" && data.name) {
address = data.name;
console.log("Found address:", address);
break;
}
} catch (e) {
console.error("Error parsing JSON:", e);
}
}
console.log("Sending response with address:", address);
sendResponse({ address: address });
}
return true;
});