From 400e6ed929c6aa4ec27e7b8b519fe4f88ecedb3b Mon Sep 17 00:00:00 2001 From: anime Date: Tue, 24 Dec 2024 15:57:47 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat(=E4=BC=98=E5=8C=96=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=86=85Google=20AdSense=20=E5=A4=84=E7=90=86):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit ed8983171355976c20d9205665f9a880f0f49dd4) --- components/GoogleAdsense.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/GoogleAdsense.js b/components/GoogleAdsense.js index f102847b..a27d25dc 100644 --- a/components/GoogleAdsense.js +++ b/components/GoogleAdsense.js @@ -182,8 +182,9 @@ const AdEmbed = () => { useEffect(() => { setTimeout(() => { // 找到所有 class 为 notion-text 且内容为 '' 的 div 元素 - const notionTextElements = document.querySelectorAll('div.notion-text') - + const notionTextElements = document.querySelectorAll( + '#article-wrapper #notion-article div.notion-text' + ) // 遍历找到的元素 notionTextElements?.forEach(element => { // 检查元素的内容是否为 '' From 5c0c02bcfb28b1bab1267d4d08a2eabd9151565c Mon Sep 17 00:00:00 2001 From: anime Date: Tue, 24 Dec 2024 16:39:58 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat(=E4=BC=98=E5=8C=96=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=86=85Google=20AdSense=E5=A4=84=E7=90=86):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 476687e2b9126de11f8bff107b73708c18093a8e) --- components/GoogleAdsense.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/components/GoogleAdsense.js b/components/GoogleAdsense.js index a27d25dc..21a60009 100644 --- a/components/GoogleAdsense.js +++ b/components/GoogleAdsense.js @@ -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 <> From 5f610d5a4e4ce00ea1162a4ca341aec27ffc2b2a Mon Sep 17 00:00:00 2001 From: anime Date: Tue, 24 Dec 2024 16:42:13 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix(=E4=BF=AE=E5=A4=8D=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=86=85Google=20AdSense=20=E5=A4=84=E7=90=86):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit f557c00894c60390123d7f60515d68112190bafe) --- components/GoogleAdsense.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/GoogleAdsense.js b/components/GoogleAdsense.js index 21a60009..32547cd9 100644 --- a/components/GoogleAdsense.js +++ b/components/GoogleAdsense.js @@ -189,7 +189,7 @@ const AdEmbed = () => { // 遍历找到的元素 notionTextElements?.forEach(element => { // 检查元素的内容是否为 '' - if (element.innerHTML.trim() === '<ins/>') { + if (element.textContent.trim() === '') { // 创建新的 元素 const newInsElement = document.createElement('ins') newInsElement.className = 'adsbygoogle w-full py-1' From bd019f19a17c1c799d963ddde611e3f150eb3aca Mon Sep 17 00:00:00 2001 From: anime Date: Sun, 29 Dec 2024 01:16:17 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat(=E7=BC=A9=E5=B0=8FMutationObserver=20o?= =?UTF-8?q?bserve=E8=8C=83=E5=9B=B4):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/GoogleAdsense.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/GoogleAdsense.js b/components/GoogleAdsense.js index 32547cd9..13ab5d2d 100644 --- a/components/GoogleAdsense.js +++ b/components/GoogleAdsense.js @@ -100,7 +100,11 @@ export const initGoogleAdsense = async ADSENSE_GOOGLE_ID => { } // 启动 MutationObserver - observer.observe(document.body, observerConfig) + observer.observe( + document.querySelector('#article-wrapper #notion-article') || + document.body, + observerConfig + ) }, 100) }) } From c7a6841c23ef88a81f6ac0d2e7892e106cd5d6d9 Mon Sep 17 00:00:00 2001 From: anime Date: Sun, 29 Dec 2024 01:29:43 +0800 Subject: [PATCH 5/5] =?UTF-8?q?feat(=E5=87=8F=E5=B0=91=20checkNodeForAds?= =?UTF-8?q?=20=E6=A3=80=E6=B5=8B=E6=AC=A1=E6=95=B0):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/GoogleAdsense.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/components/GoogleAdsense.js b/components/GoogleAdsense.js index 13ab5d2d..12aacc95 100644 --- a/components/GoogleAdsense.js +++ b/components/GoogleAdsense.js @@ -42,11 +42,7 @@ function getNodesWithAdsByGoogleClass(node) { // 检查节点及其子节点是否包含 adsbygoogle 类 function checkNodeForAds(node) { - if ( - node.nodeType === Node.ELEMENT_NODE && - node.tagName === 'INS' && - node.classList.contains('adsbygoogle') - ) { + if (node.tagName === 'INS' && node.classList.contains('adsbygoogle')) { adsNodes.push(node) } else { // 递归检查子节点