Finish cleaning out DOM (#413)

* finish cleaning out dom

* lint
This commit is contained in:
mayeaux 2021-12-02 19:22:51 +01:00 committed by GitHub
parent a842a58608
commit 82643b1f4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 22 deletions

View file

@ -390,10 +390,14 @@ function App(props: Props) {
} }
return () => { return () => {
try {
// $FlowFixMe // $FlowFixMe
document.head.removeChild(script); document.head.removeChild(script);
// $FlowFixMe // $FlowFixMe
document.head.appendChild(cmpScript); document.head.removeChild(cmpScript);
} catch (err) {
console.log(err);
}
}; };
}, []); }, []);

View file

@ -57,6 +57,8 @@ function runAds(internalFeatureEnabled, allowPreRoll, player, embedded) {
const videoElement = document.getElementsByClassName('vjs-tech')[0]; const videoElement = document.getElementsByClassName('vjs-tech')[0];
if (!videoElement) return;
// height and width of player // height and width of player
const height = videoElement.offsetHeight; const height = videoElement.offsetHeight;
const width = videoElement.offsetWidth; const width = videoElement.offsetWidth;

View file

@ -224,27 +224,10 @@ function HomePage(props: Props) {
const styleSheet = document.createElement('style'); const styleSheet = document.createElement('style');
styleSheet.type = 'text/css'; styleSheet.type = 'text/css';
styleSheet.id = 'customAniviewStyling';
styleSheet.innerText = styles; styleSheet.innerText = styles;
// $FlowFixMe // $FlowFixMe
document.head.appendChild(styleSheet); document.head.appendChild(styleSheet);
// clonedCard.style.display = 'none';
let timeoutCount = 0;
// eslint-disable-next-line no-inner-declarations
function checkForAniview() {
const aniBoxDiv = document.getElementsByClassName('homepageAdContainer')[0].querySelector('#aniBox');
if (!aniBoxDiv) {
timeoutCount += 100;
if (timeoutCount < 500) {
window.setTimeout(checkForAniview, 100);
}
} else {
clonedCard.style.display = 'block';
}
}
checkForAniview();
} }
} }
checkFlag(); checkFlag();

View file

@ -32,6 +32,11 @@ type Props = {
authenticated: boolean, authenticated: boolean,
}; };
function removeIfExists(querySelector) {
const element = document.querySelector(querySelector);
if (element) element.remove();
}
function Ads(props: Props) { function Ads(props: Props) {
const { const {
location: { pathname }, location: { pathname },
@ -69,10 +74,19 @@ function Ads(props: Props) {
return () => { return () => {
// $FlowFixMe // $FlowFixMe
document.head.removeChild(script); document.head.removeChild(script);
// clear aniview state to allow ad reload
delete window.aniplayerPos; delete window.aniplayerPos;
delete window.storageAni; delete window.storageAni;
delete window.__VIDCRUNCH_CONFIG_618bb4d28aac298191eec411__; delete window.__VIDCRUNCH_CONFIG_618bb4d28aac298191eec411__;
delete window.__player_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');
removeIfExists('#customAniviewStyling');
}; };
} catch (e) {} } catch (e) {}
} }