diff options
author | Valentin Popov <info@valentineus.link> | 2018-05-31 07:57:53 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2018-05-31 07:57:53 +0300 |
commit | 35f87f6dbe72982fd7ee922b576cddc3af06cc3a (patch) | |
tree | 14abef4ff0db443a8a40f9669ffc791ca02587e2 | |
parent | 998e30d5b29225731978b04fd0a25dffcec7bc33 (diff) | |
download | obs-somafm_current_track-35f87f6dbe72982fd7ee922b576cddc3af06cc3a.tar.xz obs-somafm_current_track-35f87f6dbe72982fd7ee922b576cddc3af06cc3a.zip |
Performance improvement
Signed-off-by: Valentin Popov <info@valentineus.link>
-rw-r--r-- | assets/javascript/script.js | 24 |
1 files changed, 17 insertions, 7 deletions
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. |