const vastTag = "https://baggymaintenance.com/d.mDF/zCdhGSNvvjZJG/Uy/_ePmY9KueZqUElAkpPeT/Ys4oMNz/c/1-O/DSkNt/N/jJg/zCNVztUi5/MAwn"; let adsLoader, adsManager, adDisplayContainer; function initAds(){ const adContainer=document.getElementById('adContainer'); const adVideo=document.getElementById('adVideo'); adDisplayContainer=new google.ima.AdDisplayContainer(adContainer,adVideo); adsLoader=new google.ima.AdsLoader(adDisplayContainer); adsLoader.addEventListener( google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, onAdsManagerLoaded,false); adsLoader.addEventListener( google.ima.AdErrorEvent.Type.AD_ERROR, onAdError,false); const adsRequest=new google.ima.AdsRequest(); adsRequest.adTagUrl=vastTag; adsRequest.linearAdSlotWidth=window.innerWidth; adsRequest.linearAdSlotHeight=window.innerHeight; adsLoader.requestAds(adsRequest); } function onAdsManagerLoaded(event){ const adContainer=document.getElementById('adContainer'); const adVideo=document.getElementById('adVideo'); adsManager=event.getAdsManager(adVideo); adsManager.addEventListener(google.ima.AdEvent.Type.COMPLETE,onAdComplete); adsManager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR,onAdError); adContainer.style.display="block"; adsManager.init(window.innerWidth,window.innerHeight,google.ima.ViewMode.NORMAL); adsManager.start(); } function onAdComplete(){ closeAd(); doUnlockCountdown(); } function onAdError(){ closeAd(); doUnlockCountdown(); } function closeAd(){ document.getElementById('adContainer').style.display="none"; if(adsManager) adsManager.destroy(); } unlockBtn.addEventListener("click",()=>{ if(!videoBlob)return; initAds(); });