-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
47 lines (42 loc) · 1.16 KB
/
Copy pathcontent.js
File metadata and controls
47 lines (42 loc) · 1.16 KB
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
const defaultBrands = [
"amazon basics",
"solimo",
"rivet",
"happy belly",
"mama bear",
"goodthreads",
"amazon essentials"
];
const api = (typeof browser !== "undefined") ? browser : chrome;
let blockedBrands = [];
api.storage.sync.get("blockedBrands")
.then((data) => {
blockedBrands = (Array.isArray(data.blockedBrands) && data.blockedBrands.length > 0)
? data.blockedBrands
: defaultBrands;
})
.catch(console.error);
api.storage.sync.get("toggle")
.then((data) => {
toggle = data.toggle || "on";
if (toggle === "on") {
hideAmazonBrands();
observer = new MutationObserver(hideAmazonBrands);
observer.observe(document.body, { childList: true, subtree: true });
}
})
.catch(console.error);
function hideAmazonBrands() {
const items = document.querySelectorAll("span, div, a");
items.forEach(el => {
if (el.innerText) {
const text = el.innerText.toLowerCase();
if (blockedBrands.some(brand => text.includes(brand.toLowerCase()))) {
const product = el.closest("[data-asin], .s-result-item, li");
if (product) {
product.style.display = "none"
}
}
}
});
}