diff --git a/ui/component/channelContent/view.jsx b/ui/component/channelContent/view.jsx index 71b32e7d2..b865cebf7 100644 --- a/ui/component/channelContent/view.jsx +++ b/ui/component/channelContent/view.jsx @@ -174,7 +174,7 @@ function ChannelContent(props: Props) { {!channelIsMine && claimsInChannel > 0 && } - {/**/} + {/* */} {!fetching && ( = 0 && elemBottom <= window.innerHeight; - return isVisible; - } - React.useEffect(() => { if (isAuthenticated || !SHOW_ADS || window.location.pathname === `/$/${PAGES.WILD_WEST}`) { return; } + // inject ad into last visible card injectAd(); }, [isAuthenticated]); diff --git a/ui/page/home/view.jsx b/ui/page/home/view.jsx index f74134e70..591aa1b9f 100644 --- a/ui/page/home/view.jsx +++ b/ui/page/home/view.jsx @@ -1,7 +1,7 @@ // @flow import * as ICONS from 'constants/icons'; import * as PAGES from 'constants/pages'; -import { SITE_NAME, SIMPLE_SITE, ENABLE_NO_SOURCE_CLAIMS } from 'config'; +import { SITE_NAME, SIMPLE_SITE, ENABLE_NO_SOURCE_CLAIMS, SHOW_ADS } from 'config'; import Ads, { injectAd } from 'web/component/ads'; import React from 'react'; import Page from 'component/page'; @@ -120,19 +120,10 @@ function HomePage(props: Props) { doFetchActiveLivestreams(); }, []); - // returns true if passed element is fully visible on screen - function isScrolledIntoView(el) { - const rect = el.getBoundingClientRect(); - const elemTop = rect.top; - const elemBottom = rect.bottom; - - // Only completely visible elements return true: - const isVisible = elemTop >= 0 && elemBottom <= window.innerHeight; - return isVisible; - } - React.useEffect(() => { - injectAd() + const shouldShowAds = SHOW_ADS && !authenticated; + // inject ad into last visible card + injectAd(shouldShowAds); }, []); return ( diff --git a/web/component/ads/view.jsx b/web/component/ads/view.jsx index 0f18ec1b4..2594b7029 100644 --- a/web/component/ads/view.jsx +++ b/web/component/ads/view.jsx @@ -170,9 +170,9 @@ function isScrolledIntoView(el) { return isVisible; } -async function injectAd() { - // don't inject on firefox android - if (isFirefoxAndroid) return; +async function injectAd(shouldShowAds: boolean) { + // don't inject on firefox android or for authenticated users or no ads on instance + if (isFirefoxAndroid || !shouldShowAds) return; // test if adblock is enabled let adBlockEnabled = false; const googleAdUrl = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';