Handle case where ad-cleanup fails (redo)

The solution didn't work 100%, only reduces the chances of happening significantly. So far, still can happen on hot-reload during development.

- Reverted 15bd26399f.
- Fix by just hiding the unoccupied aniBox
This commit is contained in:
infinite-persistence 2022-03-10 20:07:35 +08:00
parent 2dd0fc283d
commit ea8af5aa89
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
2 changed files with 16 additions and 16 deletions

View file

@ -66,6 +66,10 @@
transition: unset !important;
}
#aniBox[style*='height: 1px'] {
display: none;
}
#aniBox,
#av-container {
width: 100% !important;

View file

@ -50,20 +50,6 @@ function removeIfExists(querySelector) {
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) {
const { type = 'video', tileLayout, small, userHasPremiumPlus, className } = props;
@ -79,7 +65,6 @@ function Ads(props: Props) {
if (shouldShowAds) {
let script;
try {
clearAdElements();
script = document.createElement('script');
script.src = adConfig.url;
// $FlowFixMe
@ -88,7 +73,18 @@ function Ads(props: Props) {
return () => {
// $FlowFixMe
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) {}
}