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