Replace Vidcrunch with Adnimation

This commit is contained in:
infinite-persistence 2022-04-11 12:51:36 +08:00
parent b8cf1a6c4c
commit 6576e8317e
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -11,6 +11,8 @@ import Icon from 'component/common/icon';
import * as ICONS from 'constants/icons'; import * as ICONS from 'constants/icons';
import { LocalStorage, LS } from 'util/storage'; import { LocalStorage, LS } from 'util/storage';
const USE_ADNIMATION = true;
// prettier-ignore // prettier-ignore
const AD_CONFIGS = Object.freeze({ const AD_CONFIGS = Object.freeze({
DEFAULT: { DEFAULT: {
@ -25,9 +27,31 @@ const AD_CONFIGS = Object.freeze({
url: 'https://tg1.vidcrunch.com/api/adserver/spt?AV_TAGID=61dff05c599f1e20b01085d4&AV_PUBLISHERID=6182c8993c8ae776bd5635e9', url: 'https://tg1.vidcrunch.com/api/adserver/spt?AV_TAGID=61dff05c599f1e20b01085d4&AV_PUBLISHERID=6182c8993c8ae776bd5635e9',
tag: 'AV61dff05c599f1e20b01085d4', tag: 'AV61dff05c599f1e20b01085d4',
}, },
ADNIMATION: {
url: 'https://tg1.aniview.com/api/adserver/spt?AV_TAGID=6252bb6f28951333ec10a7a6&AV_PUBLISHERID=601d9a7f2e688a79e17c1265',
tag: 'AV6252bb6f28951333ec10a7a6',
},
}); });
// Internal use only. One-time update flag. // ****************************************************************************
// Helpers
// ****************************************************************************
function removeIfExists(querySelector) {
const element = document.querySelector(querySelector);
if (element) element.remove();
}
function resolveVidcrunchConfig() {
const mobileAds = platform.isAndroid() || platform.isIOS();
const isInEu = LocalStorage.getItem(LS.GDPR_REQUIRED) === 'true';
return isInEu ? AD_CONFIGS.EU : mobileAds ? AD_CONFIGS.MOBILE : AD_CONFIGS.DEFAULT;
}
// ****************************************************************************
// Ads
// ****************************************************************************
let ad_blocker_detected; let ad_blocker_detected;
type Props = { type Props = {
@ -44,11 +68,6 @@ type Props = {
doSetAdBlockerFound: (boolean) => void, doSetAdBlockerFound: (boolean) => void,
}; };
function removeIfExists(querySelector) {
const element = document.querySelector(querySelector);
if (element) element.remove();
}
function Ads(props: Props) { function Ads(props: Props) {
const { const {
type = 'video', type = 'video',
@ -62,11 +81,7 @@ function Ads(props: Props) {
} = props; } = props;
const [shouldShowAds, setShouldShowAds] = React.useState(resolveAdVisibility()); const [shouldShowAds, setShouldShowAds] = React.useState(resolveAdVisibility());
const mobileAds = platform.isAndroid() || platform.isIOS(); const adConfig = USE_ADNIMATION ? AD_CONFIGS.ADNIMATION : resolveVidcrunchConfig();
// this is populated from app based on location
const isInEu = LocalStorage.getItem(LS.GDPR_REQUIRED) === 'true';
const adConfig = isInEu ? AD_CONFIGS.EU : mobileAds ? AD_CONFIGS.MOBILE : AD_CONFIGS.DEFAULT;
function resolveAdVisibility() { function resolveAdVisibility() {
// 'ad_blocker_detected' will be undefined at startup. Wait until we are // 'ad_blocker_detected' will be undefined at startup. Wait until we are
@ -123,10 +138,9 @@ function Ads(props: Props) {
delete window.__player_618bb4d28aac298191eec411__; delete window.__player_618bb4d28aac298191eec411__;
// clean DOM elements from ad related elements // clean DOM elements from ad related elements
removeIfExists('[src^="https://cdn.vidcrunch.com/618bb4d28aac298191eec411.js"]'); removeIfExists('[src^="https://player.avplayer.com"]');
removeIfExists('[src^="https://player.aniview.com/script/6.1/aniview.js"]'); removeIfExists('[src^="https://gum.criteo.com"]');
removeIfExists('[id^="AVLoaderaniplayer_vidcrunch"]'); removeIfExists('[id^="AVLoaderaniview_slot"]');
removeIfExists('#av_css_id');
}; };
} catch (e) {} } catch (e) {}
} }