aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2018-05-31 05:36:28 +0300
committerValentin Popov <info@valentineus.link>2018-05-31 05:36:28 +0300
commit1bc888007bdabb0f35429db8d798567aad1c4a74 (patch)
tree3da5059a118ca71966c382e7bacb25615dedfc9d
parentd40c8863e635aeff73d6d5c7d273cd57bb5d914f (diff)
downloadobs-somafm_current_track-1bc888007bdabb0f35429db8d798567aad1c4a74.tar.xz
obs-somafm_current_track-1bc888007bdabb0f35429db8d798567aad1c4a74.zip
Other script connection
Signed-off-by: Valentin Popov <info@valentineus.link>
-rw-r--r--_includes/javascript.html77
-rw-r--r--assets/javascript/script.js74
2 files changed, 75 insertions, 76 deletions
diff --git a/_includes/javascript.html b/_includes/javascript.html
index 7b9e861..bb8d230 100644
--- a/_includes/javascript.html
+++ b/_includes/javascript.html
@@ -1,77 +1,2 @@
<!-- Updates track names -->
-<script type="text/javascript">
- '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
- * @description Updates the data on the page. Displays a pop-up window if the
- * data has changed.
- */
- function updateData(artistTrack, titleTrack) {
- /* 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 */
- document.title = artistTrack + ' - ' + titleTrack;
- 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';
- }, 5000);
- }
- }
-
- var client = new XMLHttpRequest();
- var radio = findGetParameter('radio');
- var url = '//somafm.com/songs/' + radio + '.xml';
-
- /* Processes response */
- 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 artist = current.getElementsByTagName('artist')[0].textContent;
- var title = current.getElementsByTagName('title')[0].textContent;
-
- /* Updates data */
- updateData(artist, title);
- }
- }
- };
-
- /* Update cycle */
- setInterval(function () {
- client.open('GET', url);
- client.send();
- }, 10000);
-</script>
+<script type="text/javascript" src="{{ '/assets/javascript/script.js' | relative_url | uri_escape }}"></script>
diff --git a/assets/javascript/script.js b/assets/javascript/script.js
new file mode 100644
index 0000000..6eaf1a6
--- /dev/null
+++ b/assets/javascript/script.js
@@ -0,0 +1,74 @@
+'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
+ * @description Updates the data on the page. Displays a pop-up window if the
+ * data has changed.
+ */
+function updateData(artistTrack, titleTrack) {
+ /* 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 */
+ document.title = artistTrack + ' - ' + titleTrack;
+ 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';
+ }, 10000);
+ }
+}
+
+var client = new XMLHttpRequest();
+var radio = findGetParameter('radio');
+var url = '//somafm.com/songs/' + radio + '.xml';
+
+/* Processes response */
+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 artist = current.getElementsByTagName('artist')[0].textContent;
+ var title = current.getElementsByTagName('title')[0].textContent;
+
+ /* Updates data */
+ updateData(artist, title);
+ }
+ }
+};
+
+/* Update cycle */
+setInterval(function () {
+ client.open('GET', url);
+ client.send();
+}, 15000);