import { useState, useEffect } from "react"; import { X } from "lucide-react"; import AdSense from "./adsense"; const COUNTER_KEY = "folx-interstitial-count"; const DELAY_MS = 3000; export default function InterstitialAd({ forceShow }: { forceShow?: boolean } = {}) { const [visible, setVisible] = useState(false); useEffect(() => { if (forceShow) { const timer = setTimeout(() => setVisible(true), DELAY_MS); return () => clearTimeout(timer); } const raw = sessionStorage.getItem(COUNTER_KEY); const count = raw ? parseInt(raw, 10) : 0; const next = count + 1; sessionStorage.setItem(COUNTER_KEY, next.toString()); const shouldShow = next % 2 === 1; if (!shouldShow) return; const timer = setTimeout(() => setVisible(true), DELAY_MS); return () => clearTimeout(timer); }, [forceShow]); useEffect(() => { if (visible) { document.body.style.overflow = "hidden"; } return () => { document.body.style.overflow = ""; }; }, [visible]); if (!visible) return null; return (
setVisible(false)} data-testid="interstitial-ad-overlay" >
e.stopPropagation()} data-testid="interstitial-ad-container" >
Anzeige
); }