This commit is contained in:
Raphael Wickihalder 2022-03-09 14:48:53 +01:00
commit bb9afff2d4

View file

@ -49,6 +49,20 @@ function removeIfExists(querySelector) {
if (element) element.remove(); if (element) element.remove();
} }
function clearAdElements() {
// clear aniview state to allow ad reload
delete window.aniplayerPos;
delete window.storageAni;
delete window.__VIDCRUNCH_CONFIG_618bb4d28aac298191eec411__;
delete window.__player_618bb4d28aac298191eec411__;
// clean DOM elements from ad related elements
removeIfExists('[src^="https://cdn.vidcrunch.com/618bb4d28aac298191eec411.js"]');
removeIfExists('[src^="https://player.aniview.com/script/6.1/aniview.js"]');
removeIfExists('[id^="AVLoaderaniplayer_vidcrunch"]');
removeIfExists('#av_css_id');
}
function Ads(props: Props) { function Ads(props: Props) {
const { const {
location: { pathname }, location: { pathname },
@ -71,6 +85,7 @@ function Ads(props: Props) {
if (shouldShowAds) { if (shouldShowAds) {
let script; let script;
try { try {
clearAdElements();
script = document.createElement('script'); script = document.createElement('script');
script.src = adConfig.url; script.src = adConfig.url;
// $FlowFixMe // $FlowFixMe
@ -79,18 +94,7 @@ function Ads(props: Props) {
return () => { return () => {
// $FlowFixMe // $FlowFixMe
document.head.removeChild(script); document.head.removeChild(script);
clearAdElements();
// clear aniview state to allow ad reload
delete window.aniplayerPos;
delete window.storageAni;
delete window.__VIDCRUNCH_CONFIG_618bb4d28aac298191eec411__;
delete window.__player_618bb4d28aac298191eec411__;
// clean DOM elements from ad related elements
removeIfExists('[src^="https://cdn.vidcrunch.com/618bb4d28aac298191eec411.js"]');
removeIfExists('[src^="https://player.aniview.com/script/6.1/aniview.js"]');
removeIfExists('[id^="AVLoaderaniplayer_vidcrunch"]');
removeIfExists('#av_css_id');
}; };
} catch (e) {} } catch (e) {}
} }