forked from insightbrowser/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_upsells.js
46 lines (41 loc) · 1.56 KB
/
remove_upsells.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
// not exactly ad blocking but removing known bad components
let toRemove = {
'reddit.com': ['.FooterAppUpsell', '.upsell_banner', '.TopNav__promoButton'],
'google.com': ['.FooterAppUpsell', '.upsell_banner', '.TopNav__promoButton'],
'nytimes.com': ['.expanded-dock'],
'duckduckgo.com': ['.js-atb-banner', '.atb-banner'],
}
let toClick = {
'quora.com': ['.qu-bg--blue button'],
'nytimes.com': ['.ReactModal__Overlay button', '#vi_welcome_close'],
'instagram.com': ['button span[aria-label=Close]'],
'google.com': ['div[aria-label=promo] g-flat-button', '#continueButton', '.XPromoPopup__actions .XPromoPopup__action:nth-of-type(2) button', '.XPromoPill__closeButton'],
'reddit.com': ['#continueButton', '.XPromoPopup__actions .XPromoPopup__action:nth-of-type(2) button', '.XPromoPill__closeButton']
}
const waitUntilElementExists = (selector, callback) => {
const el = document.querySelector(selector);
if (el){
return callback(el);
}
setTimeout(() => waitUntilElementExists(selector, callback), 500);
}
const removeElement = (el) => {
el.parentNode.removeChild(el)
}
const clickElement = (el) => {
el.click()
}
let hostname = new URL(window.location.href).hostname;
if (hostname.startsWith('www.')) {
hostname = hostname.slice(4)
}
if (hostname in toRemove) {
for(const element of toRemove[hostname]) {
waitUntilElementExists(element, (el) => removeElement(el));
}
}
if (hostname in toClick) {
for(const element of toClick[hostname]) {
waitUntilElementExists(element, (el) => clickElement(el));
}
}