remove adsense script when blocked
This commit is contained in:
parent
c59d827a39
commit
bce86ae8a3
1 changed files with 5 additions and 2 deletions
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue