unset ad iframe width from CSS reset. cleanup ads slots onDestroy. Ensure loaded ad scripts aren't already in head

This commit is contained in:
hobbes7878 2024-08-20 10:53:29 +01:00
parent db9645ad0e
commit e64110f4d1
2 changed files with 21 additions and 0 deletions

View file

@ -39,7 +39,25 @@
window.graphicsAdQueue = window.graphicsAdQueue || [];
window.graphicsAdQueue.push(adSlot);
}
return () => {
// @ts-ignore
const freestar = window?.freestar;
if (freestar) {
freestar.queue.push(function () {
freestar.deleteAdSlots(adId);
});
}
};
});
</script>
<div data-freestar-ad="{dataFreestarAd || null}" id="{adId}"></div>
<style lang="scss">
div {
:global(iframe) {
width: auto;
}
}
</style>

View file

@ -6,6 +6,9 @@ interface attributesInterface {
export const loadScript = (src: string, attributes?: attributesInterface) => {
const { onload, async = true } = attributes || {};
const existingScript = document.querySelector(`script[src="${src}"]`);
if (existingScript) return;
const script = document.createElement('script');
script.addEventListener('load', onload);
script.async = async;