-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
21 lines (19 loc) · 865 Bytes
/
Copy pathcontent.js
File metadata and controls
21 lines (19 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "getProductInfo") {
const titleEl = document.getElementById('productTitle');
let priceEl = document.querySelector('.a-price .a-offscreen')
|| document.querySelector('#priceblock_ourprice')
|| document.querySelector('#priceblock_dealprice')
|| document.querySelector('.a-color-price');
const imgEl = document.getElementById('landingImage') || document.querySelector('#imgTagWrapperId img');
if (titleEl) {
sendResponse({
title: titleEl.innerText.trim(),
price: priceEl ? priceEl.innerText.trim() : null,
image: imgEl ? imgEl.src : null
});
} else {
sendResponse(null);
}
}
});