-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.js
82 lines (75 loc) · 1.85 KB
/
block.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
/**
*
* @param {HTMLElement} element
*/
function unhidden(element) {
if (element.style.overflow === 'hidden') {
element.style.overflow = null;
}
}
/**
*
* @param {MutationRecord[]} mutations
* @param {MutationObserver} observer
*/
function bodyObserverCallback(mutations, observer) {
for (const mutation of mutations) {
unhidden(mutation.target);
}
}
/**
*
* @param {HTMLElement} element
*/
function rebut(element) {
if (element.classList.contains('overlay-enter-done')) {
element.style.display = null;
}
}
/**
*
* @param {MutationRecord[]} mutations
* @param {MutationObserver} observer
*/
function adObserverCallback(mutations, observer) {
for (const mutation of mutations) {
rebut(mutation.target);
}
}
/**
*
* @param {HTMLElement} element
*/
function block(element) {
element.style.display = 'none';
rebut(element);
const observer = new MutationObserver(adObserverCallback);
observer.observe(element, { attributeFilter: ['class'] });
}
/**
*
* @param {MutationRecord[]} mutations
* @param {MutationObserver} observer
*/
function portalObserverCallback(mutations, observer) {
for (const mutation of mutations) {
for (const node of mutation.addedNodes) {
if (node instanceof HTMLElement) {
block(node);
}
}
}
}
unhidden(document.body);
const bodyObserver = new MutationObserver(bodyObserverCallback);
bodyObserver.observe(document.body, { attributeFilter: ['style'] });
const portals = document.getElementsByClassName('__portal');
for (const portal of portals) {
for (const element of portal.children) {
if (element instanceof HTMLElement) {
block(element);
}
}
const observer = new MutationObserver(portalObserverCallback);
observer.observe(portal, { childList: true });
}