-
Notifications
You must be signed in to change notification settings - Fork 0
/
az_worker.js
63 lines (61 loc) · 1.25 KB
/
az_worker.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const init = () => {
try {
time = (Date.now() / 1000).toString();
title = document
.querySelector("#productTitle")
.innerHTML.substring(0, 50)
.trim();
site = "amazon";
price = (
document.querySelector(".apexPriceToPay .a-offscreen") ??
document.querySelector(".priceToPay .a-offscreen")
).innerHTML
.substring(1)
.replace(/,/g, "");
url = document.location.origin + document.location.pathname;
fetch("http://localhost:3000/addEntry", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
title: title,
site: site,
timestamp: time,
url: url,
price: price,
}),
})
.then((data) => data.json())
.then((res) => {
console.log(res);
});
console.log("Fetching entries");
fetch(
"http://localhost:3000/getEntries?" +
new URLSearchParams(
{
title: title,
},
{ method: "GET" }
)
)
.then((data) => data.json())
.then((res) => {
chrome.runtime.onMessage.addListener(function (
request,
sender,
sendResponse
) {
if (request.type === "getPrice") {
sendResponse({ body: res });
}
});
});
} catch (err) {
console.log(err);
return;
}
};
init();