-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookie-eater.js
94 lines (77 loc) · 2.35 KB
/
cookie-eater.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// ==UserScript==
// @name Cookie eater
// @namespace ilagzil
// @version 0.1
// @description Remove cookie popups
// @author You
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function removeElement(selector) {
const element = document.querySelector(selector);
if (!element) {
return false;
}
element.parentElement.removeChild(element);
return true;
}
const body = {
handle() {
this.class.handle();
this.children.handle();
},
class: {
handlers: [],
handle() {
this.handlers.forEach((handle) => handle());
},
},
children: {
handlers: [],
handle() {
this.handlers.forEach((handle) => handle());
},
},
};
const observer = new MutationObserver((mutationList) => {
if (mutationList.filter(({attributeName}) => attributeName === 'class').length) {
body.class.handle();
}
if (mutationList.filter(({type}) => type === 'childList').length) {
body.children.handle();
}
});
observer.observe(document.body, { attributes: true, childList: true });
body.class.handlers.push(
function didomi() {
const body = document.body;
if (body.classList.contains('didomi-popup-open')) {
body.classList.remove('didomi-popup-open');
removeElement('#didomi-host');
}
},
function appconsent() {
const body = document.body;
if (body.classList.contains('appconsent_noscroll')) {
body.classList.remove('appconsent_noscroll');
removeElement('#appconsent');
const handle = setInterval(
removeElement('.fig-consent-banner') && clearInterval(handle),
500,
);
}
},
);
body.class.handlers.push(
function cookiescript() {
const banner = document.querySelector('body > #cookiescript_injected');
if (banner) {
console.log('remove', banner);
document.body.removeChild(banner);
}
},
);
body.handle();
})();