Skip to content

Instantly share code, notes, and snippets.

Created October 17, 2016 00:52
Show Gist options
  • Save anonymous/195c190bb01d2eb85627881529be3636 to your computer and use it in GitHub Desktop.
Save anonymous/195c190bb01d2eb85627881529be3636 to your computer and use it in GitHub Desktop.
<div id="widget-song">...</div>
<script type="text/javascript">
var datoActual = "";
(function consultarTrack(){
var request = new XMLHttpRequest();
request.open('GET', 'http://softcloudradio.com/trackdata.php', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
// Success!
var data = request.responseText;
if (datoActual.localeCompare(data) != 0) {
datoActual = data;
var artista = datoActual.match('<body>(.*?)</body>')[1].split(",").pop().split(" - ")[0];
var cancion = datoActual.match('<body>(.*?)</body>')[1].split(",").pop().split(" - ").pop();
$("#widget-song").html(artista + " - " + cancion);
}
} else {
console.debug("error");
}
};
request.onerror = function() {
console.debug("error");
};
request.send();
setTimeout(consultarTrack,10000);
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment