2020-01-24 19:31:49 +01:00
|
|
|
// @flow
|
|
|
|
import * as PAGES from 'constants/pages';
|
2020-01-23 17:21:36 +01:00
|
|
|
import React, { useEffect } from 'react';
|
2020-01-24 19:31:49 +01:00
|
|
|
import I18nMessage from 'component/i18nMessage';
|
|
|
|
import Button from 'component/button';
|
2022-05-18 19:52:46 +02:00
|
|
|
import PremiumPlusTile from 'component/premiumPlusTile';
|
2020-03-26 22:47:07 +01:00
|
|
|
import classnames from 'classnames';
|
2022-04-14 15:21:37 +02:00
|
|
|
import useShouldShowAds from 'effects/use-should-show-ads';
|
2022-05-18 13:16:35 +02:00
|
|
|
import Icon from 'component/common/icon';
|
|
|
|
import * as ICONS from 'constants/icons';
|
2022-04-11 06:51:36 +02:00
|
|
|
|
2022-03-07 07:31:53 +01:00
|
|
|
// prettier-ignore
|
|
|
|
const AD_CONFIGS = Object.freeze({
|
2022-04-11 06:51:36 +02:00
|
|
|
ADNIMATION: {
|
2022-06-09 04:06:20 +02:00
|
|
|
// url: 'https://tg1.aniview.com/api/adserver/spt?AV_TAGID=6252bb6f28951333ec10a7a6&AV_PUBLISHERID=601d9a7f2e688a79e17c1265',
|
|
|
|
// tag: 'AV6252bb6f28951333ec10a7a6',
|
|
|
|
url: 'https://tg1.aniview.com/api/adserver/spt?AV_TAGID=62558336037e0f3df07ff0a8&AV_PUBLISHERID=601d9a7f2e688a79e17c1265',
|
2022-04-11 06:51:36 +02:00
|
|
|
tag: 'AV6252bb6f28951333ec10a7a6',
|
|
|
|
},
|
2022-06-02 17:28:40 +02:00
|
|
|
ADNIMATION_FILEPAGE: {
|
|
|
|
url: 'https://tg1.aniview.com/api/adserver/spt?AV_TAGID=62558336037e0f3df07ff0a8&AV_PUBLISHERID=601d9a7f2e688a79e17c1265',
|
2022-06-02 18:58:57 +02:00
|
|
|
tag: 'AV6252bb6f28951333ec10a7a6',
|
2022-06-02 17:28:40 +02:00
|
|
|
},
|
2022-03-07 07:31:53 +01:00
|
|
|
});
|
2022-01-14 20:21:17 +01:00
|
|
|
|
2022-04-11 06:51:36 +02:00
|
|
|
// ****************************************************************************
|
|
|
|
// Helpers
|
|
|
|
// ****************************************************************************
|
|
|
|
|
|
|
|
function removeIfExists(querySelector) {
|
|
|
|
const element = document.querySelector(querySelector);
|
|
|
|
if (element) element.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ****************************************************************************
|
|
|
|
// Ads
|
|
|
|
// ****************************************************************************
|
|
|
|
|
2020-01-24 19:31:49 +01:00
|
|
|
type Props = {
|
2020-03-26 22:47:07 +01:00
|
|
|
type: string,
|
2022-06-02 17:28:40 +02:00
|
|
|
filePage?: boolean,
|
2022-03-07 13:11:28 +01:00
|
|
|
tileLayout?: boolean,
|
2022-05-18 19:52:46 +02:00
|
|
|
small?: boolean,
|
|
|
|
className?: string,
|
|
|
|
noFallback?: boolean,
|
|
|
|
// --- redux ---
|
2022-05-30 12:50:15 +02:00
|
|
|
isAdBlockerFound: ?boolean,
|
2022-03-09 19:05:37 +01:00
|
|
|
userHasPremiumPlus: boolean,
|
2022-05-18 19:52:46 +02:00
|
|
|
userCountry: string,
|
2022-03-14 18:49:15 +01:00
|
|
|
doSetAdBlockerFound: (boolean) => void,
|
2020-01-24 19:31:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function Ads(props: Props) {
|
2022-05-18 19:52:46 +02:00
|
|
|
const {
|
|
|
|
type = 'video',
|
2022-06-02 17:28:40 +02:00
|
|
|
filePage = false,
|
2022-05-18 19:52:46 +02:00
|
|
|
tileLayout,
|
|
|
|
small,
|
2022-05-30 12:50:15 +02:00
|
|
|
isAdBlockerFound,
|
2022-05-18 19:52:46 +02:00
|
|
|
userHasPremiumPlus,
|
|
|
|
userCountry,
|
|
|
|
className,
|
|
|
|
noFallback,
|
|
|
|
doSetAdBlockerFound,
|
|
|
|
} = props;
|
2022-03-09 19:05:37 +01:00
|
|
|
|
2022-05-30 12:50:15 +02:00
|
|
|
const shouldShowAds = useShouldShowAds(userHasPremiumPlus, userCountry, isAdBlockerFound, doSetAdBlockerFound);
|
2022-06-02 17:28:40 +02:00
|
|
|
const adConfig = filePage ? AD_CONFIGS.ADNIMATION_FILEPAGE : AD_CONFIGS.ADNIMATION;
|
2021-11-23 16:21:33 +01:00
|
|
|
|
2021-11-30 23:01:03 +01:00
|
|
|
// add script to DOM
|
2020-01-23 17:21:36 +01:00
|
|
|
useEffect(() => {
|
2022-01-04 17:55:59 +01:00
|
|
|
if (shouldShowAds) {
|
2021-01-22 00:57:29 +01:00
|
|
|
let script;
|
2020-03-26 22:47:07 +01:00
|
|
|
try {
|
2021-11-23 16:21:33 +01:00
|
|
|
script = document.createElement('script');
|
2022-03-07 07:31:53 +01:00
|
|
|
script.src = adConfig.url;
|
2020-03-26 22:47:07 +01:00
|
|
|
// $FlowFixMe
|
2021-12-01 04:17:28 +01:00
|
|
|
document.head.appendChild(script);
|
2020-03-26 22:47:07 +01:00
|
|
|
|
2021-11-30 23:01:03 +01:00
|
|
|
return () => {
|
2020-02-05 06:13:29 +01:00
|
|
|
// $FlowFixMe
|
2021-11-30 23:01:03 +01:00
|
|
|
document.head.removeChild(script);
|
2022-03-10 13:07:35 +01:00
|
|
|
|
|
|
|
// clear aniview state to allow ad reload
|
|
|
|
delete window.aniplayerPos;
|
|
|
|
delete window.storageAni;
|
|
|
|
delete window.__player_618bb4d28aac298191eec411__;
|
|
|
|
|
2022-05-23 14:06:25 +02:00
|
|
|
const styles = document.querySelectorAll('body > style');
|
|
|
|
styles.forEach((s) => {
|
|
|
|
// We are asking Adnimation to supply us with a specific ID or
|
|
|
|
// pattern so that our query wouldn't break when they change their
|
|
|
|
// script. For now, this is the "best effort".
|
|
|
|
if (s.innerText && s.innerText.startsWith('#outbrain')) {
|
|
|
|
s.remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-03-10 13:07:35 +01:00
|
|
|
// clean DOM elements from ad related elements
|
2022-04-11 06:51:36 +02:00
|
|
|
removeIfExists('[src^="https://player.avplayer.com"]');
|
|
|
|
removeIfExists('[src^="https://gum.criteo.com"]');
|
|
|
|
removeIfExists('[id^="AVLoaderaniview_slot"]');
|
2021-11-30 23:01:03 +01:00
|
|
|
};
|
|
|
|
} catch (e) {}
|
2020-02-05 06:13:29 +01:00
|
|
|
}
|
2022-06-02 17:28:40 +02:00
|
|
|
}, [shouldShowAds, adConfig]);
|
2020-03-26 22:47:07 +01:00
|
|
|
|
|
|
|
const adsSignInDriver = (
|
|
|
|
<I18nMessage
|
|
|
|
tokens={{
|
2022-03-15 03:38:45 +01:00
|
|
|
sign_up_for_premium: (
|
|
|
|
<Button button="link" label={__('Get Odysee Premium+')} navigate={`/$/${PAGES.ODYSEE_MEMBERSHIP}`} />
|
2020-03-26 22:47:07 +01:00
|
|
|
),
|
|
|
|
}}
|
|
|
|
>
|
2022-05-18 13:16:35 +02:00
|
|
|
%sign_up_for_premium% for an ad free experience.
|
2020-03-26 22:47:07 +01:00
|
|
|
</I18nMessage>
|
|
|
|
);
|
2020-01-23 17:21:36 +01:00
|
|
|
|
2022-05-18 19:52:46 +02:00
|
|
|
if (type === 'video') {
|
|
|
|
if (shouldShowAds) {
|
|
|
|
return (
|
2022-03-07 13:11:28 +01:00
|
|
|
<div
|
2022-05-18 19:52:46 +02:00
|
|
|
className={classnames('ads ads__claim-item', className, {
|
|
|
|
'ads__claim-item--tile': tileLayout,
|
2022-03-07 13:11:28 +01:00
|
|
|
})}
|
|
|
|
>
|
2022-05-18 19:52:46 +02:00
|
|
|
<div className="ad__container">
|
2022-06-09 04:06:20 +02:00
|
|
|
{/* <div id={adConfig.tag} /> */}
|
|
|
|
<div id="AV6252bb6f28951333ec10a7a6" />
|
|
|
|
<div id="AV62558336037e0f3df07ff0a8" />
|
2022-05-18 13:16:35 +02:00
|
|
|
</div>
|
2022-05-18 19:52:46 +02:00
|
|
|
<div
|
|
|
|
className={classnames('ads__claim-text', {
|
|
|
|
'ads__claim-text--small': small,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<div className="ads__title">
|
|
|
|
{__('Ad')}
|
|
|
|
<br />
|
|
|
|
{__('Hate these?')}
|
|
|
|
{/* __('No ads, a custom badge and access to exclusive features, try Odysee Premium!') */}
|
|
|
|
</div>
|
|
|
|
<div className="ads__subtitle">
|
|
|
|
<Icon icon={ICONS.UPGRADE} />
|
|
|
|
{adsSignInDriver}
|
|
|
|
</div>
|
2022-05-18 13:16:35 +02:00
|
|
|
</div>
|
2022-03-07 13:11:28 +01:00
|
|
|
</div>
|
2022-05-18 19:52:46 +02:00
|
|
|
);
|
|
|
|
} else if (!noFallback) {
|
|
|
|
return <PremiumPlusTile tileLayout={tileLayout} />;
|
|
|
|
}
|
2021-01-22 00:57:29 +01:00
|
|
|
}
|
2022-01-04 18:43:35 +01:00
|
|
|
|
2022-03-07 13:11:28 +01:00
|
|
|
return null;
|
2022-01-04 18:43:35 +01:00
|
|
|
}
|
|
|
|
|
2022-03-15 03:38:45 +01:00
|
|
|
export default Ads;
|