Google Adsense
This commit is contained in:
tangly1024
2021-12-17 21:03:20 +08:00
parent d4d969a10d
commit 43de0a80d4
8 changed files with 88 additions and 47 deletions

View File

@@ -102,6 +102,31 @@ const initTheme = (theme, changeTheme) => {
}
}
export function handleRouteChange (url) {
console.log('路由变化', url)
initGoogleAdsense()
}
/**
* 初始化谷歌广告
*/
// let activeAdsCount = 0
function initGoogleAdsense () {
const ads = document.getElementsByClassName('adsbygoogle').length
// const newAdsCount = ads - activeAdsCount
// console.log(`Start: 总广告${ads}, 已激活${activeAdsCount} 新广告${newAdsCount}`)
const newAdsCount = ads
if (newAdsCount > 0) {
for (let i = 0; i <= newAdsCount; i++) {
try {
(adsbygoogle = window.adsbygoogle || []).push({})
} catch (e) {
}
}
}
}
/**
* 读取默认主题
* @returns {*}