1(()=>{'use strict'; 2const q=(r,s)=>r.querySelector(s),qa=(r,s)=>[...r.querySelectorAll(s)]; 3const safe=s=>s==null?'':String(s); 4const initRoot=ROOT=>{ 5 if(ROOT.dataset.svvdInit==='1')return;ROOT.dataset.svvdInit='1'; 6 const dataNode=q(ROOT,'.svvd-data');let DATA={};try{DATA=JSON.parse(dataNode?.textContent||'{}')}catch(e){} 7 const ITEMS=Array.isArray(DATA.items)?DATA.items:[],CONF=DATA.conf||{}; 8 const track=q(ROOT,'.svvd-stories-track'),listEl=q(ROOT,'.svvd-listitems'),h1=q(ROOT,'.svvd-h1'),desc=q(ROOT,'.svvd-desc'),read=q(ROOT,'.svvd-read'); 9 const poster=q(ROOT,'.svvd-poster'),posterImg=q(ROOT,'.svvd-poster-img'),video=q(ROOT,'.svvd-video'),fsBtn=q(ROOT,'.svvd-fsbtn'); 10 const advBadge=q(ROOT,'.svvd-advbadge'),advState=q(ROOT,'.svvd-advstate'),advTime=q(ROOT,'.svvd-advtime'),wrap=q(ROOT,'.svvd-playerwrap'); 11 let idx=0,badgeTimer=0,adsLoader=null,adsManager=null,adDisplayContainer=null,adSlot=null,adRequestedCycle=false,adsPlaying=false,adsStarted=false,providerList=[],providerIndex=0,noFillWatchdog=0,requestInFlight=false,contentTimeBeforeAd=0,contentPausedForAd=false,delayedAdHandle=0; 12 const log=(...a)=>{if(CONF.debug)try{console.log('[SVVD]',...a)}catch(e){}}; 13 const setPoster=u=>{posterImg.style.backgroundImage=u?'url("'+String(u).replace(/"/g,'%22')+'")':'none';try{video.poster=u||''}catch(e){}}; 14 const clamp=()=>{const col=q(ROOT,'.svvd-playercol');if(!col||!listEl)return;listEl.style.maxHeight=Math.max(200,Math.floor(col.getBoundingClientRect().height-36))+'px'}; 15 const badgeOff=()=>{clearInterval(badgeTimer);badgeTimer=0;if(advBadge)advBadge.style.display='none';if(advState)advState.textContent='';if(advTime)advTime.textContent=''}; 16 const badgeLoading=()=>{if(!advBadge)return;advBadge.style.display='block';advState.textContent='Caricamentoâ¦';advTime.textContent=''}; 17 const badgePlaying=s=>{if(!advBadge)return;advBadge.style.display='block';advState.textContent='Pubblicità ';advTime.textContent=s?('⢠'+s+'s'):''}; 18 const countdown=d=>{clearInterval(badgeTimer);let r=Math.max(0,Math.ceil(+d||0));badgePlaying(r);if(!r)return;badgeTimer=setInterval(()=>{r--;badgePlaying(Math.max(0,r));if(r<=0){clearInterval(badgeTimer);badgeTimer=0}},1000)}; 19 const showAdSlot=on=>{if(adSlot)adSlot.style.display=on?'block':'none'}; 20 const ensureAudio=()=>{try{if(video.muted)video.muted=false;if((video.volume||0)<.05)video.volume=1}catch(e){}try{adsManager?.setVolume?.(1)}catch(e){}}; 21 const playContent=()=>{poster.style.display='none';video.play().catch(()=>{})}; 22 poster?.addEventListener('click',playContent);poster?.addEventListener('keydown',e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault();playContent()}}); 23 fsBtn?.addEventListener('click',()=>{try{if(video.requestFullscreen)return video.requestFullscreen();if(video.webkitEnterFullscreen)return video.webkitEnterFullscreen();if(wrap?.requestFullscreen)return wrap.requestFullscreen()}catch(e){}}); 24 const select=(i,autoplay)=>{if(!ITEMS.length)return;idx=Math.max(0,Math.min(ITEMS.length-1,i));const it=ITEMS[idx];qa(listEl,'.svvd-item').forEach((n,k)=>n.classList.toggle('active',k===idx));h1.textContent=safe(it.title);desc.textContent=safe(it.excerpt);read.href=it.post_url||'#';setPoster(it.poster||'');poster.style.display='flex';try{video.pause();video.removeAttribute('src');video.load()}catch(e){}resetAd(true);video.src=it.video||'';video.load();setTimeout(clamp,60);if(autoplay)playContent()}; 25 const buildStories=()=>{if(!track)return;track.innerHTML='';ITEMS.forEach((it,i)=>{const d=document.createElement('div');d.className='svvd-story';d.innerHTML='<div class="svvd-storyimg"><div class="svvd-playbadge">â¶</div></div><div class="svvd-storyt"></div>';q(d,'.svvd-storyimg').style.backgroundImage=it.poster?'url("'+String(it.poster).replace(/"/g,'%22')+'")':'none';q(d,'.svvd-storyt').textContent=safe(it.title);d.addEventListener('click',()=>select(i,true));track.append(d)})}; 26 const buildList=()=>{listEl.innerHTML='';ITEMS.forEach((it,i)=>{const r=document.createElement('div');r.className='svvd-item';r.innerHTML='<div class="thumb"></div><div class="twrap"><div class="t"></div><div class="e"></div></div>';q(r,'.thumb').style.backgroundImage=it.poster?'url("'+String(it.poster).replace(/"/g,'%22')+'")':'none';q(r,'.t').textContent=safe(it.title);q(r,'.e').textContent=safe(it.excerpt);r.addEventListener('click',()=>select(i,true));listEl.append(r)});setTimeout(clamp,60)}; 27 const waitVivimedia=cb=>{let n=0;(function c(){n++;if(typeof window.playerVMstring==='string'&&window.playerVMstring.length)return cb((CONF.vivimedia_base||'')+window.playerVMstring);if(n>=30)return cb('');setTimeout(c,200)})()}; 28 const providerUrl=(p,cb)=>
28{if(p==='viralize')return cb(CONF.viralize_url||'');if(p==='vivimedia')return waitVivimedia(cb);if(p==='custom')return cb(providerIndex===0?(CONF.primary_url||''):(CONF.fallback_url||''));cb('')}; 29 const providers=()=>{const p=CONF.primary||'custom',f=CONF.fallback||'custom';providerList=[p];if(f&&f!==p)providerList.push(f);providerIndex=0}; 30 const ensureIMA=()=>{if(!CONF.enabled||CONF.engine!=='ima')return false;if(adsLoader)return true;if(!(window.google&&google.ima))return false;if(!adSlot){adSlot=document.createElement('div');adSlot.className='svvd-adslot';wrap.append(adSlot)}adDisplayContainer=new google.ima.AdDisplayContainer(adSlot,video);adsLoader=new google.ima.AdsLoader(adDisplayContainer);adsLoader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,onManager,false);adsLoader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR,onAdError,false);return true}; 31 const destroy=()=>{clearTimeout(noFillWatchdog);noFillWatchdog=0;try{adsManager?.destroy()}catch(e){}adsManager=null;requestInFlight=false}; 32 const resume=()=>{destroy();adsPlaying=false;adsStarted=false;badgeOff();showAdSlot(false);if(contentPausedForAd&&Number.isFinite(contentTimeBeforeAd))try{video.currentTime=contentTimeBeforeAd}catch(e){}contentPausedForAd=false;video.play().catch(()=>{})}; 33 const nextProvider=reason=>{destroy();badgeOff();showAdSlot(false);if(providerIndex<providerList.length-1){providerIndex++;requestAds(providerList[providerIndex])}else{log('NO-FILL',reason);resume()}}; 34 function onAdError(e){nextProvider(e?.getError?.()?.getMessage?.()||'AD_ERROR')} 35 function onManager(e){try{adsManager=e.getAdsManager(video);adsManager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR,onAdError);adsManager.addEventListener(google.ima.AdEvent.Type.STARTED,ev=>{clearTimeout(noFillWatchdog);requestInFlight=false;adsPlaying=adsStarted=true;contentTimeBeforeAd=video.currentTime||0;contentPausedForAd=true;video.pause();showAdSlot(true);ensureAudio();let d=0;try{d=ev.getAd()?.getDuration?.()||0}catch(x){}countdown(d)});adsManager.addEventListener(google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED,()=>adsStarted?resume():nextProvider('resume-before-start'));adsManager.addEventListener(google.ima.AdEvent.Type.ALL_ADS_COMPLETED,()=>adsStarted?resume():nextProvider('completed-before-start'));const r=wrap.getBoundingClientRect(),w=Math.max(320,Math.round(r.width||640)),h=Math.max(180,Math.round(r.height||360));adsManager.init(w,h,google.ima.ViewMode.NORMAL);adsManager.start()}catch(x){nextProvider('MANAGER_START_FAIL')}} 36 const requestAds=p=>{if(!ensureIMA()){badgeOff();return}try{adDisplayContainer.initialize()}catch(e){}badgeLoading();requestInFlight=true;providerUrl(p,url=>{if(!url)return nextProvider('NO_VAST_URL');const r=wrap.getBoundingClientRect(),req=new google.ima.AdsRequest(),w=Math.max(320,Math.round(r.width||640)),h=Math.max(180,Math.round(r.height||360));req.adTagUrl=url;req.linearAdSlotWidth=w;req.linearAdSlotHeight=h;req.nonLinearAdSlotWidth=w;req.nonLinearAdSlotHeight=h;try{adsLoader.requestAds(req);noFillWatchdog=setTimeout(()=>{if(requestInFlight&&!adsStarted)nextProvider('watchdog')},9000)}catch(e){nextProvider('REQUEST_FAIL')}})}; 37 const playXml=async()=>{badgeLoading();try{const r=await fetch(CONF.vast_endpoint,{credentials:'same-origin',headers:{'X-WP-Nonce':CONF.nonce||''}}),j=await r.json(),ad=j?.ad;if(!ad?.media){badgeOff();return}const resumeAt=video.currentTime||0,ov=video.volume,om=video.muted,overlay=document.createElement('div'),av=document.createElement('video'),st=document.createElement('div');overlay.className='svvd-adslot svvd-xml-ad';overlay.style.display='block';av.src=ad.media;av.playsInline=true;av.autoplay=true;av.controls=false;av.muted=om;av.volume=ov;st.className='svvd-xml-badge';st.textContent='Pubblicità ';overlay.append(av,st);wrap.append(overlay);video.pause();const done=()=>{av.pause();overlay.remove();badgeOff();video.currentTime=resumeAt;video.play().catch(()=>{})};av.addEventListener('timeupdate',()=>{if(Number.isFinite(av.duration)){const left=Math.max(0,Math.ceil(av.duration-av.currentTime));badgePlaying(left)}});av.addEventListener('ended',done,{once:true});av.addEventListener('error',done,{once:true});await av.play()}catch(e){badgeOff();video.play().catch(()=>{})}}; 38 const maybeAd=()=>
38{if(!CONF.enabled||adRequestedCycle||adsPlaying)return;clearTimeout(delayedAdHandle);delayedAdHandle=setTimeout(()=>{if(video.paused||video.ended)return;adRequestedCycle=true;if(CONF.engine==='xml')playXml();else{providers();requestAds(providerList[0]||'custom')}},Math.max(0,+CONF.delay_ms||3000))}; 39 function resetAd(hard){clearTimeout(delayedAdHandle);clearTimeout(noFillWatchdog);badgeOff();adRequestedCycle=false;adsPlaying=false;adsStarted=false;providerIndex=0;requestInFlight=false;if(hard)destroy()} 40 video.addEventListener('playing',maybeAd);video.addEventListener('pause',()=>clearTimeout(delayedAdHandle));video.addEventListener('ended',()=>{clearTimeout(delayedAdHandle);badgeOff();if(ITEMS.length)select((idx+1)%ITEMS.length,true)}); 41 wrap?.addEventListener('click',ensureAudio,{passive:true});wrap?.addEventListener('touchend',ensureAudio,{passive:true}); 42 if(!ITEMS.length){h1.textContent='Nessun video trovato (solo video allegati ad articoli).';desc.textContent='';poster.style.display='none';badgeOff()}else{buildStories();buildList();select(0,false)} 43 window.addEventListener('resize',()=>setTimeout(clamp,60),{passive:true}); 44}; 45document.querySelectorAll('.svvd-root[data-svvd="1"]').forEach(initRoot); 46})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.