diff --git a/blog.config.js b/blog.config.js index 3025250d..65683d0d 100644 --- a/blog.config.js +++ b/blog.config.js @@ -332,6 +332,8 @@ const BLOG = { // <---- 站点统计 + // START---->营收相关 + // 谷歌广告 ADSENSE_GOOGLE_ID: process.env.NEXT_PUBLIC_ADSENSE_GOOGLE_ID || '', // 谷歌广告ID e.g ca-pub-xxxxxxxxxxxxxxxx ADSENSE_GOOGLE_TEST: process.env.NEXT_PUBLIC_ADSENSE_GOOGLE_TEST || false, // 谷歌广告ID测试模式,这种模式获取假的测试广告,用于开发 https://www.tangly1024.com/article/local-dev-google-adsense @@ -340,6 +342,12 @@ const BLOG = { ADSENSE_GOOGLE_SLOT_NATIVE: process.env.NEXT_PUBLIC_ADSENSE_GOOGLE_SLOT_NATIVE || '4980048999', // Google AdScene>广告>按单元广告>新建原生广告 ADSENSE_GOOGLE_SLOT_AUTO: process.env.NEXT_PUBLIC_ADSENSE_GOOGLE_SLOT_AUTO || '8807314373', // Google AdScene>广告>按单元广告>新建展示广告 (自动广告) + // 万维广告 + AD_WWADS_ID: process.env.NEXT_PUBLIC_WWAD_ID || null, // https://wwads.cn/ 创建您的万维广告单元ID + AD_WWADS_BLOCK_DETECT: process.env.NEXT_PUBLIC_WWADS_AD_BLOCK_DETECT || false, // 是否开启WWADS广告屏蔽插件检测,开启后会在广告位上以文字提示 @see https://github.com/bytegravity/whitelist-wwads + + // END<----营收相关 + // 自定义配置notion数据库字段名 NOTION_PROPERTY_NAME: { password: process.env.NEXT_PUBLIC_NOTION_PROPERTY_PASSWORD || 'password', diff --git a/components/AdBlockDetect.js b/components/AdBlockDetect.js new file mode 100644 index 00000000..00758a08 --- /dev/null +++ b/components/AdBlockDetect.js @@ -0,0 +1,40 @@ +import { useEffect } from 'react' + +/** + * 检测广告插件 + * @returns + */ +export default function AdBlockDetect() { + useEffect(() => { + // 如果检测到广告屏蔽插件 + function ABDetected() { + if (!document) { + return + } + const wwadsCns = document.getElementsByClassName('wwads-cn') + if (wwadsCns && wwadsCns.length > 0) { + for (const wwadsCn of wwadsCns) { + wwadsCn.insertAdjacentHTML('beforeend', "
为了本站的长期运营,请将我们的网站加入广告拦截器的白名单,感谢您的支持!万维广告
") + } + } + }; + + // check document ready + function docReady(t) { + document.readyState === 'complete' || + document.readyState === 'interactive' + ? setTimeout(t, 1) + : document.addEventListener('DOMContentLoaded', t) + } + + // check if wwads' fire function was blocked after document is ready with 3s timeout (waiting the ad loading) + docReady(function () { + setTimeout(function () { + if (window._AdBlockInit === undefined) { + ABDetected() + } + }, 3000) + }) + }, []) + return null +} diff --git a/components/CommonScript.js b/components/CommonScript.js index 4ee0f12c..2d6afe14 100644 --- a/components/CommonScript.js +++ b/components/CommonScript.js @@ -38,6 +38,8 @@ const CommonScript = () => { /> )} + {BLOG.AD_WWADS_ID && } + {BLOG.COMMENT_CUSDIS_APP_ID &&