-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
75 lines (64 loc) · 1.82 KB
/
content.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
// Store target selectors
const MODAL_SELECTOR = '.fixed.inset-0.bg-gray-900.bg-opacity-75.flex.items-center.justify-center.z-50.p-4';
const HEADER_SELECTOR = '.bg-gradient-to-br.from-indigo-900.via-purple-900.to-indigo-800.text-white.py-8.px-4.md\\:py-12.md\\:px-10.shadow-lg.relative.overflow-hidden';
// Immediately inject blocking styles
function injectBlockingStyles() {
const style = document.createElement('style');
style.textContent = `
${MODAL_SELECTOR},
${HEADER_SELECTOR} {
display: none !important;
visibility: hidden !important;
opacity: 0 !important;
pointer-events: none !important;
}
`;
// Insert styles as early as possible
(document.head || document.documentElement).appendChild(style);
}
// Direct element removal function
function removeModalElement() {
const modal = document.querySelector(MODAL_SELECTOR);
if (modal) {
modal.remove();
return true;
}
return false;
}
// Performance-optimized observer
function createObserver() {
let timeoutId = null;
const observer = new MutationObserver((mutations) => {
if (timeoutId) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(() => {
if (removeModalElement()) {
observer.disconnect();
}
}, 0);
});
return observer;
}
// Initialize everything
function initialize() {
injectBlockingStyles();
if (!removeModalElement()) {
const observer = createObserver();
observer.observe(document.documentElement, {
childList: true,
subtree: true
});
setTimeout(() => {
observer.disconnect();
}, 5000);
}
}
// Run initialization as early as possible
initialize();
// Add a backup check when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initialize);
} else {
initialize();
}