From ba9dd452f2b6675a1065b2ca08354b026958b1ab Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 31 May 2018 06:02:59 +0400 Subject: Added the ability to use different radio stations Signed-off-by: Valentin Popov --- assets/javascript/script.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'assets/javascript/script.js') diff --git a/assets/javascript/script.js b/assets/javascript/script.js index f2eb794..c955567 100644 --- a/assets/javascript/script.js +++ b/assets/javascript/script.js @@ -1,5 +1,25 @@ 'use strict'; +/** + * @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; +} + /** * @param {String} artistTrack - Artist of the track * @param {String} titleTrack - Name of the track @@ -14,8 +34,8 @@ function updateData(artistTrack, titleTrack) { if (artistElement.textContent !== artistTrack || titleElement.textContent !== titleTrack) { /* Updates text */ - artistElement.innerHTML = artistTrack; - titleElement.innerHTML = titleTrack; + artistElement.textContent = artistTrack; + titleElement.textContent = titleTrack; /* Displays a pop-up window */ displayElement.style['animation-name'] = 'fadeIn'; @@ -28,7 +48,8 @@ function updateData(artistTrack, titleTrack) { } var client = new XMLHttpRequest(); -var url = 'https://somafm.com/songs/defcon.xml'; +var radio = findGetParameter('radio'); +var url = '//somafm.com/songs/' + radio + '.xml'; /* Processes response */ client.onload = function () { -- cgit v1.2.3