feat(优化文章内Google AdSense处理):

(cherry picked from commit 476687e2b9126de11f8bff107b73708c18093a8e)
This commit is contained in:
anime
2024-12-24 16:39:58 +08:00
parent 400e6ed929
commit 5c0c02bcfb

View File

@@ -44,6 +44,7 @@ function getNodesWithAdsByGoogleClass(node) {
function checkNodeForAds(node) {
if (
node.nodeType === Node.ELEMENT_NODE &&
node.tagName === 'INS' &&
node.classList.contains('adsbygoogle')
) {
adsNodes.push(node)
@@ -71,7 +72,7 @@ export const initGoogleAdsense = async ADSENSE_GOOGLE_ID => {
).then(url => {
setTimeout(() => {
// 页面加载完成后加载一次广告
const ads = document.getElementsByClassName('adsbygoogle')
const ads = document.querySelectorAll('ins.adsbygoogle')
if (window.adsbygoogle && ads.length > 0) {
requestAd(Array.from(ads))
}
@@ -206,8 +207,6 @@ const AdEmbed = () => {
element?.parentNode?.replaceChild(newInsElement, element)
}
})
requestAd()
}, 1000)
}, [])
return <></>