Füge Beobachtungslogik hinzu, um eingefügte Anzeigenknoten zu erkennen und in den Platzhalter zu verschieben
This commit is contained in:
@@ -121,6 +121,52 @@ async function renderPropeller() {
|
|||||||
const placeholder = document.createElement('div');
|
const placeholder = document.createElement('div');
|
||||||
placeholder.className = 'propeller-ad-placeholder';
|
placeholder.className = 'propeller-ad-placeholder';
|
||||||
adContainer.value.appendChild(placeholder);
|
adContainer.value.appendChild(placeholder);
|
||||||
|
|
||||||
|
// Observe the document for injected ad nodes and relocate them into our placeholder
|
||||||
|
const observeAndRelocate = () => {
|
||||||
|
const parent = document.body;
|
||||||
|
try {
|
||||||
|
const observer = new MutationObserver(mutations => {
|
||||||
|
for (const m of mutations) {
|
||||||
|
for (const node of Array.from(m.addedNodes)) {
|
||||||
|
if (!(node instanceof HTMLElement)) continue;
|
||||||
|
const src = (node.tagName === 'IFRAME' && node.getAttribute('src')) || '';
|
||||||
|
const isAdNode = src.includes('nap5k') || (node.dataset && node.dataset.zone === propSlotId) || /nap5k|propel|propeller|inpage|push/i.test(node.className + ' ' + node.id);
|
||||||
|
if (isAdNode) {
|
||||||
|
try {
|
||||||
|
placeholder.innerHTML = '';
|
||||||
|
placeholder.appendChild(node);
|
||||||
|
node.style.maxWidth = '100%';
|
||||||
|
node.style.display = 'block';
|
||||||
|
observer.disconnect();
|
||||||
|
try { window.dispatchEvent(new CustomEvent('ads:relocated',{detail:{provider:'propeller',zone:propSlotId}})); } catch {}
|
||||||
|
return;
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Failed to relocate ad node', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
observer.observe(parent, { childList: true, subtree: true });
|
||||||
|
|
||||||
|
// Check existing iframes right away
|
||||||
|
const existing = Array.from(document.querySelectorAll('iframe')).find(f => (f.src || '').includes('nap5k'));
|
||||||
|
if (existing) {
|
||||||
|
placeholder.innerHTML = '';
|
||||||
|
placeholder.appendChild(existing);
|
||||||
|
observer.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Failsafe: stop observing after 6s
|
||||||
|
setTimeout(() => observer.disconnect(), 6000);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('observeAndRelocate error', e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Start observing shortly after script insertion to allow provider to run
|
||||||
|
setTimeout(observeAndRelocate, 100);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('Propeller ad load failed', err);
|
console.warn('Propeller ad load failed', err);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user