remove adsense script when blocked

This commit is contained in:
zeppi 2021-02-09 13:55:06 -05:00 committed by jessopb
parent c59d827a39
commit bce86ae8a3

View file

@ -84,10 +84,10 @@ function Ads(props: Props) {
useEffect(() => { useEffect(() => {
let script; let script;
const GOOGLE_AD_ELEMENT_ID = 'googleadscriptid';
if (SHOW_ADS && type === 'google' && !isBlocked) { if (SHOW_ADS && type === 'google' && !isBlocked) {
const d = document; const d = document;
if (!d.getElementById('googleadscriptid')) { if (!d.getElementById(GOOGLE_AD_ELEMENT_ID)) {
try { try {
const s = 'script'; const s = 'script';
let fjs = d.getElementsByTagName(s)[0]; let fjs = d.getElementsByTagName(s)[0];
@ -105,6 +105,9 @@ function Ads(props: Props) {
(window.adsbygoogle = window.adsbygoogle || []).push({}); (window.adsbygoogle = window.adsbygoogle || []).push({});
} }
}, 1000); }, 1000);
} else if (isBlocked) {
let fjs = document.getElementById(GOOGLE_AD_ELEMENT_ID);
if (fjs) fjs.remove();
} }
return () => { return () => {
if (googleInit) { if (googleInit) {