mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-24 15:09:51 +00:00
feature:
不蒜子调整
This commit is contained in:
29
components/GoogleAdsense.js
Normal file
29
components/GoogleAdsense.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { useRouter } from 'next/router'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
export default function GoogleAdsense () {
|
||||
const initGoogleAdsense = () => {
|
||||
const ads = document.getElementsByClassName('adsbygoogle').length
|
||||
const newAdsCount = ads
|
||||
if (newAdsCount > 0) {
|
||||
for (let i = 0; i <= newAdsCount; i++) {
|
||||
try {
|
||||
// eslint-disable-next-line no-undef
|
||||
(adsbygoogle = window.adsbygoogle || []).push({})
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const router = useRouter()
|
||||
useEffect(() => {
|
||||
initGoogleAdsense()
|
||||
router.events.on('routeChangeComplete', initGoogleAdsense)
|
||||
return () => {
|
||||
router.events.off('routeChangeComplete', initGoogleAdsense)
|
||||
}
|
||||
}, [router.events])
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user