diff --git a/attached_assets/image_1772358837576.png b/attached_assets/image_1772358837576.png new file mode 100644 index 0000000..23762f3 Binary files /dev/null and b/attached_assets/image_1772358837576.png differ diff --git a/client/src/components/adsense.tsx b/client/src/components/adsense.tsx index 42e7bf5..f82e3e2 100644 --- a/client/src/components/adsense.tsx +++ b/client/src/components/adsense.tsx @@ -10,6 +10,7 @@ interface AdSenseProps { style?: Record; layout?: string; layoutKey?: string; + onAdStatus?: (filled: boolean) => void; } export default function AdSense({ @@ -20,10 +21,10 @@ export default function AdSense({ style, layout, layoutKey, + onAdStatus, }: AdSenseProps) { const adRef = useRef(null); const pushed = useRef(false); - const [adLoaded, setAdLoaded] = useState(false); useEffect(() => { if (pushed.current) return; @@ -34,17 +35,29 @@ export default function AdSense({ } catch (e) { } - const timer = setTimeout(() => { - if (adRef.current) { - const ins = adRef.current; - const filled = ins.getAttribute("data-ad-status") === "filled" || - ins.children.length > 0 || - ins.clientHeight > 0; - setAdLoaded(filled); - } - }, 3000); - - return () => clearTimeout(timer); + if (onAdStatus) { + const checkAd = () => { + if (adRef.current) { + const ins = adRef.current; + const status = ins.getAttribute("data-ad-status"); + if (status === "filled") { + onAdStatus(true); + return; + } + if (status === "unfilled") { + onAdStatus(false); + return; + } + if (ins.clientHeight > 10) { + onAdStatus(true); + return; + } + } + }; + const t1 = setTimeout(checkAd, 2000); + const t2 = setTimeout(checkAd, 5000); + return () => { clearTimeout(t1); clearTimeout(t2); }; + } }, []); return ( @@ -104,12 +117,15 @@ export function MultiplexAd() { } export function SidebarAd() { + const [visible, setVisible] = useState(false); + return ( -
+
setVisible(filled)} />