2018-05-31 06:36:28 +04:00
|
|
|
'use strict';
|
|
|
|
|
2018-05-31 08:10:16 +04:00
|
|
|
var client = new XMLHttpRequest();
|
2018-05-31 08:29:16 +04:00
|
|
|
var channel = findGetParameter('channel');
|
2018-05-31 08:57:53 +04:00
|
|
|
var duration = getInterval('duration');
|
|
|
|
var interval = getInterval('interval');
|
2018-05-31 08:10:16 +04:00
|
|
|
|
2018-05-31 08:57:53 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @description Processes the incoming packet.
|
|
|
|
*/
|
2018-05-31 08:10:16 +04:00
|
|
|
client.onload = function () {
|
|
|
|
if (client.readyState === client.DONE) {
|
|
|
|
if (this.status === 200 && this.responseXML !== null) {
|
|
|
|
/* Gets current track */
|
|
|
|
var current = this.responseXML.getElementsByTagName('song')[0];
|
|
|
|
var artistTrack = current.getElementsByTagName('artist')[0].textContent;
|
|
|
|
var titleTrack = current.getElementsByTagName('title')[0].textContent;
|
|
|
|
|
|
|
|
/* Gets items on the page */
|
|
|
|
var displayElement = document.getElementById('display');
|
|
|
|
var artistElement = document.getElementById('artist');
|
|
|
|
var titleElement = document.getElementById('title');
|
|
|
|
|
|
|
|
if (artistElement.textContent !== artistTrack || titleElement.textContent !== titleTrack) {
|
|
|
|
/* Updates text */
|
|
|
|
artistElement.textContent = artistTrack;
|
|
|
|
titleElement.textContent = titleTrack;
|
|
|
|
|
|
|
|
/* Displays a pop-up window */
|
|
|
|
displayElement.style['animation-name'] = 'fadeIn';
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
/* Removes a pop-up window */
|
|
|
|
displayElement.style['animation-name'] = 'fadeOut';
|
2018-05-31 08:57:53 +04:00
|
|
|
}, duration);
|
2018-05-31 08:10:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-31 08:57:53 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @description Cyclical sending a request to update the information.
|
|
|
|
*/
|
|
|
|
setInterval(function tick() {
|
|
|
|
client.open('GET', '//somafm.com/songs/' + channel + '.xml');
|
2018-05-31 08:10:16 +04:00
|
|
|
client.send();
|
2018-05-31 08:57:53 +04:00
|
|
|
return tick;
|
|
|
|
}(), interval);
|
2018-05-31 08:10:16 +04:00
|
|
|
|
2018-05-31 06:36:28 +04:00
|
|
|
/**
|
2018-05-31 08:57:53 +04:00
|
|
|
* @function
|
2018-05-31 06:36:28 +04:00
|
|
|
* @param {String} parameterName - Variable name
|
|
|
|
* @returns {String} Value of variable
|
|
|
|
* @description Searches for the value of the GET variable on the page.
|
|
|
|
*/
|
|
|
|
function findGetParameter(parameterName) {
|
|
|
|
var result = null;
|
|
|
|
var tmp = [];
|
|
|
|
|
|
|
|
var items = window.location.search.substr(1).split('&');
|
|
|
|
for (var index = 0; index < items.length; index++) {
|
|
|
|
tmp = items[index].split('=');
|
|
|
|
if (tmp[0] === parameterName) {
|
|
|
|
result = decodeURIComponent(tmp[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-31 08:57:53 +04:00
|
|
|
* @function
|
2018-05-31 08:10:16 +04:00
|
|
|
* @param {String} parameterName - Variable name
|
|
|
|
* @returns {Number} Timer value, default 10 seconds
|
|
|
|
* @description Gets the settings for the specified timer.
|
2018-05-31 06:36:28 +04:00
|
|
|
*/
|
2018-05-31 08:10:16 +04:00
|
|
|
function getInterval(parameterName) {
|
|
|
|
var value = findGetParameter(parameterName);
|
|
|
|
var interval = parseInt(value, 10);
|
|
|
|
var result = 10000;
|
2018-05-31 06:36:28 +04:00
|
|
|
|
2018-05-31 08:10:16 +04:00
|
|
|
if (isNaN(interval) === false) {
|
|
|
|
result = interval;
|
2018-05-31 06:36:28 +04:00
|
|
|
}
|
|
|
|
|
2018-05-31 08:10:16 +04:00
|
|
|
return result;
|
|
|
|
}
|