-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
44 lines (40 loc) · 1.7 KB
/
popup.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
const overTop = document.querySelector(".over-top");
let poupArr = [];
function popup() {
chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
var activeTab = tabs[0];
chrome.storage.local.get("produtInfo").then((obj) => {
obj.produtInfo ? (poupArr = obj.produtInfo) : [];
console.log(poupArr);
obj?.produtInfo.forEach((element, i) => {
html = ` <div id='${i}' class="info flex">
<img src="${element.otherInfo.imageLink}" alt="img-1">
<div class="title-desc">
<h2>${element.otherInfo.title}</h2>
<h3>₹${element.otherInfo.finalPrice}</h3>
<div class="buttons flex hidden">
<a class="delete-btn buy-now" href="#" role="button">Delete</a>
<a class="buy-now" href="${element.url}" target="_blank" role="button">Buy Now</a>
</div>
</div>
</div>`;
overTop.insertAdjacentHTML("beforeend", html);
});
const infoo = document.querySelectorAll(".info"); // from here buttons toggle class start which hides and show the button in view
infoo.forEach((val, i) => {
val.addEventListener("click", () => {
val.querySelector(".buttons").classList.toggle("hidden");
});
}); //here button toggle calss ends
const deleteNow = document.querySelectorAll(".delete-btn");
deleteNow.forEach((element, i) => {
element.addEventListener("click", (e) => {
element.closest(".info").remove();
poupArr.splice(i, 1);
chrome.storage.local.set({ produtInfo: poupArr });
});
});
}); //here the chrome storage api code ends
});
}
popup();