From 0f61ba7c0801e3f0d045d29819e097394d6eaeee Mon Sep 17 00:00:00 2001 From: IngridRegina Date: Sat, 20 Jun 2020 15:35:01 +0300 Subject: [PATCH 1/6] fix to show the correct song title --- script.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/script.js b/script.js index 4606a97..6e70dea 100644 --- a/script.js +++ b/script.js @@ -6,11 +6,16 @@ function update(){ var json_obj = JSON.parse(json_text); var playing = ''; var first = getFirstPlaying(json_obj); - if (first == null) {} - else if (first.artist != undefined) { + + if (first == null) { + playing = 'Mitte munnigi ei mängi prg'; + } + else if (first != null && first.artist != undefined) { playing = first.artist + ' - '; + playing += first.title; + } else { + playing += first.title; } - playing += first.title; var nowPlaying = playing; update_field('on-air', playing); update_listeners(json_obj); @@ -26,8 +31,11 @@ function update_field(field, data){ } function update_listeners(json_obj){ - var nowPlaying = getFirstPlaying(json_obj); - update_field('listeners1', nowPlaying.listeners); + var nowPlaying = getFirstPlaying(json_obj); + + if(nowPlaying != null) { + update_field('listeners1', nowPlaying.listeners); + } } function autoupdate(){ @@ -45,11 +53,16 @@ function reset_bg(){ function getFirstPlaying(jsonObj){ var sources = jsonObj.icestats.source; + var masterStreams = [ + '/live', + ] + for(o=0; o < sources.length; o++) { - if (sources[o].title != undefined) { + if (sources[o].title != undefined && masterStreams.some(stream=>sources[o].listenurl.endsWith(stream))) { //check if source has a title key AND belongs to masterStreams return sources[o]; - } + } } + return null; } From c45175f639e64416cdfe555231bf9de1f2c3ffcc Mon Sep 17 00:00:00 2001 From: IngridRegina Date: Sat, 20 Jun 2020 15:50:06 +0300 Subject: [PATCH 2/6] adding the other masterStreams :) --- script.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/script.js b/script.js index 6e70dea..0e56f0d 100644 --- a/script.js +++ b/script.js @@ -55,6 +55,9 @@ function getFirstPlaying(jsonObj){ var sources = jsonObj.icestats.source; var masterStreams = [ '/live', + '/sai', + '/siinus', + '/viido' ] for(o=0; o < sources.length; o++) { From 6ab19c819fd665576ceadeef195301985b74d2a4 Mon Sep 17 00:00:00 2001 From: IngridRegina Date: Sat, 20 Jun 2020 16:07:55 +0300 Subject: [PATCH 3/6] removing unnecessary part from else if --- script.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/script.js b/script.js index 0e56f0d..a02307e 100644 --- a/script.js +++ b/script.js @@ -10,7 +10,7 @@ function update(){ if (first == null) { playing = 'Mitte munnigi ei mängi prg'; } - else if (first != null && first.artist != undefined) { + else if (first.artist != undefined) { playing = first.artist + ' - '; playing += first.title; } else { @@ -55,9 +55,6 @@ function getFirstPlaying(jsonObj){ var sources = jsonObj.icestats.source; var masterStreams = [ '/live', - '/sai', - '/siinus', - '/viido' ] for(o=0; o < sources.length; o++) { From 23dbdcd44154d6ee3d5652b170e2740dc26c98d8 Mon Sep 17 00:00:00 2001 From: IngridRegina Date: Sat, 20 Jun 2020 16:26:03 +0300 Subject: [PATCH 4/6] removing trailing spaces for siinus --- script.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/script.js b/script.js index a02307e..df10d60 100644 --- a/script.js +++ b/script.js @@ -10,10 +10,10 @@ function update(){ if (first == null) { playing = 'Mitte munnigi ei mängi prg'; } - else if (first.artist != undefined) { - playing = first.artist + ' - '; - playing += first.title; - } else { + else if (first.artist != undefined) { + playing = first.artist + ' - '; + playing += first.title; + } else { playing += first.title; } var nowPlaying = playing; @@ -31,16 +31,16 @@ function update_field(field, data){ } function update_listeners(json_obj){ - var nowPlaying = getFirstPlaying(json_obj); + var nowPlaying = getFirstPlaying(json_obj); if(nowPlaying != null) { update_field('listeners1', nowPlaying.listeners); - } + } } function autoupdate(){ update(); - setInterval(function(){ update(); }, 30000); + setInterval(function(){ update(); }, 30000); } function change_bg(id){ @@ -60,9 +60,9 @@ function getFirstPlaying(jsonObj){ 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 return sources[o]; - } + } } - + return null; } From 2b7b3d53d332f67037888366b41657d89bb9ca85 Mon Sep 17 00:00:00 2001 From: IngridRegina Date: Sat, 20 Jun 2020 16:38:29 +0300 Subject: [PATCH 5/6] correcting code format --- script.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/script.js b/script.js index df10d60..f997f4d 100644 --- a/script.js +++ b/script.js @@ -9,8 +9,7 @@ function update(){ if (first == null) { playing = 'Mitte munnigi ei mängi prg'; - } - else if (first.artist != undefined) { + } else if (first.artist != undefined) { playing = first.artist + ' - '; playing += first.title; } else { From 4416f0452e92bc94877bc5b115a5acb14f90bdac Mon Sep 17 00:00:00 2001 From: IngridRegina Date: Sat, 20 Jun 2020 17:17:30 +0300 Subject: [PATCH 6/6] adding other masterStreams again --- script.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index f997f4d..3acc9cb 100644 --- a/script.js +++ b/script.js @@ -32,7 +32,7 @@ function update_field(field, data){ function update_listeners(json_obj){ var nowPlaying = getFirstPlaying(json_obj); - if(nowPlaying != null) { + if (nowPlaying != null) { update_field('listeners1', nowPlaying.listeners); } } @@ -54,6 +54,9 @@ function getFirstPlaying(jsonObj){ var sources = jsonObj.icestats.source; var masterStreams = [ '/live', + '/sai', + '/siinus', + '/viido', ] for(o=0; o < sources.length; o++) {