43 lines
958 B
TypeScript
43 lines
958 B
TypeScript
"use client"
|
|
|
|
import { useEffect } from 'react'
|
|
|
|
declare global {
|
|
interface Window {
|
|
adsbygoogle: any[]
|
|
}
|
|
}
|
|
|
|
interface AdBannerProps {
|
|
className?: string
|
|
}
|
|
|
|
export default function AdBanner({ className = "" }: AdBannerProps) {
|
|
useEffect(() => {
|
|
try {
|
|
// 延迟确保AdSense脚本已加载
|
|
const timer = setTimeout(() => {
|
|
if (typeof window !== 'undefined' && window.adsbygoogle) {
|
|
(window.adsbygoogle = window.adsbygoogle || []).push({})
|
|
}
|
|
}, 100)
|
|
|
|
return () => clearTimeout(timer)
|
|
} catch (error) {
|
|
console.error('AdSense error:', error)
|
|
}
|
|
}, [])
|
|
|
|
return (
|
|
<div className={`w-full my-8 ${className}`}>
|
|
<ins
|
|
className="adsbygoogle"
|
|
style={{ display: 'block' }}
|
|
data-ad-client="ca-pub-7296634171837358"
|
|
data-ad-slot="1080203791"
|
|
data-ad-format="auto"
|
|
data-full-width-responsive="true"
|
|
/>
|
|
</div>
|
|
)
|
|
}
|