more touchups
This commit is contained in:
parent
e3395e31ba
commit
cac05d5714
4 changed files with 9 additions and 28 deletions
|
@ -182,22 +182,12 @@ function DiscoverPage(props: Props) {
|
|||
);
|
||||
}
|
||||
|
||||
// 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(() => {
|
||||
if (isAuthenticated || !SHOW_ADS || window.location.pathname === `/$/${PAGES.WILD_WEST}`) {
|
||||
return;
|
||||
}
|
||||
|
||||
// inject ad into last visible card
|
||||
injectAd();
|
||||
}, [isAuthenticated]);
|
||||
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in a new issue