Zaznava praznega oglasa: steje dejanski okvir oglasa, ne rezervirana visina
This commit is contained in:
parent
9d20f0da8e
commit
9a75e88932
@ -50,15 +50,21 @@ export default function AdSense({
|
||||
clearTimeout(timer);
|
||||
onAdStatus(filled);
|
||||
};
|
||||
// Visina samega <ins> ni dokaz - nekatere enote imajo rezerviran prostor.
|
||||
// Napolnjen oglas ima notri okvir (iframe) z dejansko visino.
|
||||
const hasFrame = () => {
|
||||
const f = ins.querySelector("iframe");
|
||||
return !!f && (f as HTMLIFrameElement).clientHeight > 10;
|
||||
};
|
||||
const check = () => {
|
||||
const st = ins.getAttribute("data-ad-status") || "";
|
||||
if (st === "filled") return decide(true);
|
||||
if (st.startsWith("unfill")) return decide(false);
|
||||
if (ins.clientHeight > 10) return decide(true);
|
||||
if (hasFrame()) return decide(true);
|
||||
};
|
||||
const obs = new MutationObserver(check);
|
||||
obs.observe(ins, { attributes: true, attributeFilter: ["data-ad-status", "style"] });
|
||||
const timer = setTimeout(() => decide(ins.clientHeight > 10), 6000);
|
||||
obs.observe(ins, { attributes: true, childList: true, subtree: true, attributeFilter: ["data-ad-status", "style"] });
|
||||
const timer = setTimeout(() => decide(hasFrame()), 6000);
|
||||
check();
|
||||
return () => { obs.disconnect(); clearTimeout(timer); };
|
||||
}, []);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user