aboutsummaryrefslogtreecommitdiff
path: root/assets/javascript/script.js
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2018-05-31 03:48:42 +0300
committerValentin Popov <info@valentineus.link>2018-05-31 03:48:42 +0300
commitb83ea600ecbf2da7eba0cbbd8dc216b254e0c195 (patch)
tree174aa334ae0d73268c0f3aa6b75acbfe8522bfaf /assets/javascript/script.js
parent8156027eaacc7a11aacdbdc4763d843afb68c5fc (diff)
downloadobs-somafm_current_track-b83ea600ecbf2da7eba0cbbd8dc216b254e0c195.tar.xz
obs-somafm_current_track-b83ea600ecbf2da7eba0cbbd8dc216b254e0c195.zip
Renaming a file
Signed-off-by: Valentin Popov <info@valentineus.link>
Diffstat (limited to 'assets/javascript/script.js')
-rw-r--r--assets/javascript/script.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/assets/javascript/script.js b/assets/javascript/script.js
new file mode 100644
index 0000000..d17c60c
--- /dev/null
+++ b/assets/javascript/script.js
@@ -0,0 +1,52 @@
+'use strict';
+
+/**
+ * @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.innerHTML !== artistTrack || titleElement.innerHTML !== titleTrack) {
+ /* Updates text */
+ artistElement.innerHTML = artistTrack;
+ titleElement.innerHTML = 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 url = 'https://somafm.com/songs/defcon.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);