-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
70 lines (56 loc) · 2.26 KB
/
main.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
(function() {
const targetElement = document.querySelector('#ubwidget');
//const targetElement = document.querySelector('#cvt'); // alternate target
function removeElements(elements) {
elements.forEach(elem => elem.parentNode.removeChild(elem));
}
// Function to inject CSS
function injectCSS(cssString) {
const style = document.createElement('style');
style.textContent = cssString;
document.head.appendChild(style);
}
// Inject the CSS
injectCSS(`
.ub-emb-close { display:none; }
.ub-emb-iframe-wrapper.ub-emb-visible {
width: 100% !important;
height: 100% !important;
}
`);
function adjustContainerStyles(container) {
const iframes = container.querySelectorAll('iframe');
iframes.forEach(iframe => {
iframe.classList.add('ub-emb-visible');
iframe.setAttribute("scrolling", "no");
iframe.style.width = '100% !important';
iframe.style.height = '100% !important';
});
const scrollWrappers = container.querySelectorAll('.ub-emb-scroll-wrapper');
scrollWrappers.forEach(wrapper => {
Object.assign(wrapper.style, {
position: 'absolute',
padding: '0',
transition: 'none',
overflow: 'hidden'
});
});
}
function handlePotentialDOMChange() {
const container = document.querySelector('.ub-emb-iframe-wrapper');
if (container && container.querySelector('iframe')) {
moveContainerToTarget(container);
adjustContainerStyles(container);
// Optional: Remove backdrops
// removeElements(document.querySelectorAll('.ub-emb-overlay .ub-emb-backdrop'));
removeElements(document.querySelectorAll('.ub-emb-container'));
observer.disconnect(); // Stop observing once our task is complete
}
}
function moveContainerToTarget(container) {
targetElement.innerHTML = '';
targetElement.appendChild(container);
}
const observer = new MutationObserver(handlePotentialDOMChange);
observer.observe(document.body, { childList: true, subtree: true });
})();