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(() => {
|
React.useEffect(() => {
|
||||||
if (isAuthenticated || !SHOW_ADS || window.location.pathname === `/$/${PAGES.WILD_WEST}`) {
|
if (isAuthenticated || !SHOW_ADS || window.location.pathname === `/$/${PAGES.WILD_WEST}`) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// inject ad into last visible card
|
||||||
injectAd();
|
injectAd();
|
||||||
}, [isAuthenticated]);
|
}, [isAuthenticated]);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// @flow
|
// @flow
|
||||||
import * as ICONS from 'constants/icons';
|
import * as ICONS from 'constants/icons';
|
||||||
import * as PAGES from 'constants/pages';
|
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 Ads, { injectAd } from 'web/component/ads';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Page from 'component/page';
|
import Page from 'component/page';
|
||||||
|
@ -120,19 +120,10 @@ function HomePage(props: Props) {
|
||||||
doFetchActiveLivestreams();
|
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(() => {
|
React.useEffect(() => {
|
||||||
injectAd()
|
const shouldShowAds = SHOW_ADS && !authenticated;
|
||||||
|
// inject ad into last visible card
|
||||||
|
injectAd(shouldShowAds);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -170,9 +170,9 @@ function isScrolledIntoView(el) {
|
||||||
return isVisible;
|
return isVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function injectAd() {
|
async function injectAd(shouldShowAds: boolean) {
|
||||||
// don't inject on firefox android
|
// don't inject on firefox android or for authenticated users or no ads on instance
|
||||||
if (isFirefoxAndroid) return;
|
if (isFirefoxAndroid || !shouldShowAds) return;
|
||||||
// test if adblock is enabled
|
// test if adblock is enabled
|
||||||
let adBlockEnabled = false;
|
let adBlockEnabled = false;
|
||||||
const googleAdUrl = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
|
const googleAdUrl = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
|
||||||
|
|
Loading…
Reference in a new issue