-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
42 lines (32 loc) · 943 Bytes
/
Copy pathbackground.js
File metadata and controls
42 lines (32 loc) · 943 Bytes
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
const adSelectors = [
'div[id^="ads"]',
'div[class^="ads"]',
'div[id*="adsbygoogle"]',
'div[class*="adsbygoogle"]',
'ins[id*="adsbygoogle"]',
'ins[class*="adsbygoogle"]',
'[aria-label^="Ad"]'
];
const adBlocker = new MutationObserver(() => {
currUrl = window.location.href;
chrome.storage.sync.get({ whitelist: [] }, function (data) {
const whitelist = data.whitelist;
blockAds = true;
whitelist.forEach((url) => {
if (currUrl.startsWith(url)) {
blockAds = false;
}
});
if (!blockAds) return;
adSelectors.forEach((selector) => {
const adElements = document.querySelectorAll(selector);
adElements.forEach((element) => {
element.style.display = 'none';
});
});
});
});
adBlocker.observe(document.body, {
childList: true,
subtree: true,
});