1 2(function(){ 3"use strict"; 4let url="https://api.money.it/quotazioni/tickersummary.php"; 5let selector="#quotCarousel .embla__container" 6let lastRates=[]; 7let working=false; 8let urlparams=new URLSearchParams(); 9urlparams.append('category','carousel'); 10urlparams.append('ttl',30); 11fetch(url+'?'+urlparams.toString()) 12.then(x=>x.json()) 13.then(data=>{ 14buildCarousel(data.rates); 15lastRates=data.rates; 16update(); 17}) 18.catch(e=>console.warn('Carousel fetch failed',e)); 19function buildCarousel(rates){ 20let container=document.querySelector(selector); 21if(!container)return; 22for(var i=0;i<rates.length;i++){ 23var $quot=container.querySelector('[data-id='+normalize(rates[i].name)+']'); 24if($quot){ 25$quot.querySelector(".titolo a").textContent=rates[i].name; 26$quot.querySelector(".bid").textContent=rates[i].bid.toLocaleString('it-IT',{minimumFractionDigits:2,maximumFractionDigits:2}); 27if(rates[i].changepct>0){ 28$quot.querySelector(".changepct").classList.add("up"); 29$quot.querySelector(".pct").textContent="+"+rates[i].changepct.toFixed(2).replace('.',',')+'%'; 30}else{ 31$quot.querySelector(".changepct").classList.add("down"); 32$quot.querySelector(".pct").textContent=rates[i].changepct.toFixed(2).replace('.',',')+'%'; 33} 34} 35} 36} 37function reset($el){ 38setTimeout(function(){ 39$el.classList.remove("up"); 40$el.classList.remove("down"); 41},1000); 42} 43function normalize(s){ 44if(!s){ 45return""; 46} 47return s.replace(/[ &-'\/]/gi,'').toLowerCase(); 48} 49function update(){ 50setInterval(function(){ 51if(!working){ 52working=true; 53var maxTime=0; 54if(lastRates.length>0){ 55maxTime=lastRates.map(x=>x.time).reduce((a,b)=>Math.max(a,b)); 56} 57let urlparams=new URLSearchParams(); 58urlparams.append('category','carousel2'); 59urlparams.append('ttl',30); 60urlparams.append('maxtime',maxTime); 61fetch(url+'?'+urlparams.toString()) 62.then(x=>x.json()) 63.then(data=>{ 64let $carousel=document.querySelector(selector); 65if(!$carousel)return; 66for(var i=0;i<data.rates.length;i++){ 67let rate=data.rates[i]; 68let $rate=$carousel.querySelector('[data-id='+normalize(rate.name)+']'); 69if($rate){ 70let previousIndex=lastRates.findIndex(x=>x.name==rate.name); 71var previous=lastRates[previousIndex]; 72if(previous.bid!=rate.bid){ 73var $spanBid=$rate.querySelector(".bid"); 74var $spanChangepct=$rate.querySelector(".changepct"); 75var $spanChangepctText=$rate.querySelector(".pct"); 76$spanBid.textContent=rate.bid.toLocaleString('it-IT',{minimumFractionDigits:2,maximumFractionDigits:2}); 77if(rate.bid>previous.bid){ 78$spanBid.classList.add("up"); 79}else{ 80$spanBid.classList.add("down"); 81} 82reset($spanBid); 83if(rate.changepct!=previous.changepct){ 84$spanChangepct.classList.remove("up"); 85$spanChangepct.classList.remove("down"); 86if(rate.changepct>0){ 87$spanChangepct.classList.add("up"); 88$spanChangepctText.textContent="+"+rate.changepct.toFixed(2).replace('.',',')+"%"; 89}else{ 90$spanChangepct.classList.add("down"); 91$spanChangepctText.textContent=rate.changepct.toFixed(2).replace('.',',')+"%"; 92} 93} 94lastRates[previousIndex]=rate; 95} 96} 97} 98working=false; 99}) 100.catch(e=>{ 101working=false; 102console.warn('Carousel update fetch failed',e); 103}); 104} 105},30000); 106} 107}());
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.