function addTimeStamp() { const tstmp = new Date(); return tstmp.getTime(); } function wonder_RefreshTitleArtist() { const xhr = new XMLHttpRequest(); const url = "https://onair.e-radio.gr/whatson/athensparty/wonder/NowOnAir.xml?timestamp=" + addTimeStamp(); xhr.open("GET", url, true); xhr.responseType = "document"; xhr.onload = function() { if (xhr.status >= 200 && xhr.status < 300) { wonder_ShowTitleArtist(xhr.responseXML); } }; xhr.send(); } function wonder_ShowTitleArtist(xml) { const songs = xml.getElementsByTagName("Song"); for (let i = 0; i < songs.length; i++) { document.getElementById("wonderTitle").innerHTML = songs[i].getAttribute("title"); } const artists = xml.getElementsByTagName("Artist"); for (let i = 0; i < artists.length; i++) { document.getElementById("wonderArtist").innerHTML = artists[i].getAttribute("name"); } } var oRefreshwonder = window.setInterval(wonder_RefreshTitleArtist, 50000); // Adding an event listener for script load document.addEventListener('scriptLoaded', function() { wonder_RefreshTitleArtist(); });