From 35f87f6dbe72982fd7ee922b576cddc3af06cc3a Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 31 May 2018 08:57:53 +0400 Subject: Performance improvement Signed-off-by: Valentin Popov --- assets/javascript/script.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'assets/javascript/script.js') diff --git a/assets/javascript/script.js b/assets/javascript/script.js index 28da8ce..8ca0faa 100644 --- a/assets/javascript/script.js +++ b/assets/javascript/script.js @@ -2,9 +2,13 @@ var client = new XMLHttpRequest(); var channel = findGetParameter('channel'); -var url = '//somafm.com/songs/' + channel + '.xml'; +var duration = getInterval('duration'); +var interval = getInterval('interval'); -/* Processes response */ +/** + * @function + * @description Processes the incoming packet. + */ client.onload = function () { if (client.readyState === client.DONE) { if (this.status === 200 && this.responseXML !== null) { @@ -29,19 +33,24 @@ client.onload = function () { setTimeout(function () { /* Removes a pop-up window */ displayElement.style['animation-name'] = 'fadeOut'; - }, getInterval('duration')); + }, duration); } } } }; -/* Update cycle */ -setInterval(function () { - client.open('GET', url); +/** + * @function + * @description Cyclical sending a request to update the information. + */ +setInterval(function tick() { + client.open('GET', '//somafm.com/songs/' + channel + '.xml'); client.send(); -}, getInterval('interval')); + return tick; +}(), interval); /** + * @function * @param {String} parameterName - Variable name * @returns {String} Value of variable * @description Searches for the value of the GET variable on the page. @@ -62,6 +71,7 @@ function findGetParameter(parameterName) { } /** + * @function * @param {String} parameterName - Variable name * @returns {Number} Timer value, default 10 seconds * @description Gets the settings for the specified timer. -- cgit v1.2.3