Kahtlane FM web page http://kahtlane.eu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.6 KiB

7 years ago
function update(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var json_text = xhttp.responseText;
var json_obj = JSON.parse(json_text);
var playing = '';
var first = getFirstPlaying(json_obj);
if (first == null) {
playing = 'Mitte munnigi ei mängi prg';
}
else if (first.artist != undefined) {
playing = first.artist + ' - ';
playing += first.title;
} else {
playing += first.title;
7 years ago
}
var nowPlaying = playing;
update_field('on-air', playing);
update_listeners(json_obj);
}
};
xhttp.open("GET", "http://kahtlane.eu:8000/status-json.xsl", true);
xhttp.send();
}
function update_field(field, data){
document.getElementById(field).innerHTML = data;
return 'ok';
}
function update_listeners(json_obj){
var nowPlaying = getFirstPlaying(json_obj);
if(nowPlaying != null) {
update_field('listeners1', nowPlaying.listeners);
}
7 years ago
}
function autoupdate(){
update();
setInterval(function(){ update(); }, 30000);
7 years ago
}
function change_bg(id){
document.body.style.backgroundImage = "url('http://i.imgur.com/" + id + ".jpg')";
}
function reset_bg(){
document.body.style.backgroundImage = "url('http://i.imgur.com/BkSL2KJ.png')";
}
function getFirstPlaying(jsonObj){
var sources = jsonObj.icestats.source;
var masterStreams = [
'/live',
]
7 years ago
for(o=0; o < sources.length; o++) {
if (sources[o].title != undefined && masterStreams.some(stream=>sources[o].listenurl.endsWith(stream))) { //check if source has a title key AND belongs to masterStreams
7 years ago
return sources[o];
}
7 years ago
}
7 years ago
return null;
}