import { useEffect, useRef, useState } from "react"; type AdFormat = "auto" | "fluid" | "rectangle" | "horizontal" | "vertical" | "autorelaxed"; interface AdSenseProps { slot: string; format?: AdFormat; responsive?: boolean; className?: string; style?: Record; layout?: string; layoutKey?: string; onAdStatus?: (filled: boolean) => void; } export default function AdSense({ slot, format = "auto", responsive = true, className = "", style, layout, layoutKey, onAdStatus, }: AdSenseProps) { const adRef = useRef(null); const pushed = useRef(false); useEffect(() => { if (pushed.current) return; try { const adsbygoogle = (window as any).adsbygoogle || []; adsbygoogle.push({}); pushed.current = true; } catch (e) { } 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 (
); } export function ArticleCardAd() { return (
); } export function InArticleAd() { return ( ); } export function MultiplexAd() { return (
); } export function SidebarAd() { const [visible, setVisible] = useState(false); return (
setVisible(filled)} />
); }