'use strict';

/* global Connector */

var INFO_TRACK = 3;
var INFO_ARTIST = 4;
var INFO_DURATION = 5;

var trackInfo = null;

function updateTrackInfo() {
	trackInfo = JSON.parse(localStorage.getItem('audio_v10_track'));
}

/**
 * Decodes HTML entities in given text string
 * @param  {String} str String with HTML entities
 * @return {String}     Decoded string
 */
var decodeHtmlEntity = function(str) {
	if (str === null) {
		return null;
	}

	return str.replace(/&#(\d+);/g, function(match, dec) {
		return String.fromCharCode(dec);
	});
};


Connector.artistTrackSelector = '.top_audio_player_title';
Connector.playerSelector = '#top_audio_player';

Connector.getArtist = function () {
			updateTrackInfo();
			return decodeHtmlEntity(trackInfo[INFO_ARTIST]);
		};
Connector.getTrack = function () {
			updateTrackInfo();
			return decodeHtmlEntity(trackInfo[INFO_TRACK]);
		};
Connector.getCurrentTime = function () {
			updateTrackInfo();
			var progress = parseFloat(localStorage.getItem('audio_v10_progress'));
			return Math.round(parseInt(trackInfo[INFO_DURATION]) * progress);
		};
Connector.getDuration = function () {
			updateTrackInfo();
			return parseInt(trackInfo[INFO_DURATION]);
		};
Connector.isPlaying = function() {
	return $(this.playerSelector).hasClass('top_audio_player_playing');
		};

@@ -540,17 +540,16 @@
 %7D);%0A%7D;%0A%0A
-%0A
 Connecto
@@ -599,16 +599,17 @@
 title';%0A
+%0A
 Connecto
@@ -677,34 +677,32 @@
 = function () %7B%0A
-%09%09
 %09updateTrackInfo
@@ -697,34 +697,32 @@
 ateTrackInfo();%0A
-%09%09
 %09return decodeHt
@@ -751,29 +751,28 @@
 O_ARTIST%5D);%0A
-%09%09
 %7D;%0A
+%0A
 Connector.ge
@@ -786,34 +786,32 @@
 = function () %7B%0A
-%09%09
 %09updateTrackInfo
@@ -806,34 +806,32 @@
 ateTrackInfo();%0A
-%09%09
 %09return decodeHt
@@ -859,29 +859,28 @@
 FO_TRACK%5D);%0A
-%09%09
 %7D;%0A
+%0A
 Connector.ge
@@ -900,34 +900,32 @@
 = function () %7B%0A
-%09%09
 %09updateTrackInfo
@@ -928,18 +928,16 @@
 Info();%0A
-%09%09
 %09var pro
@@ -1000,18 +1000,16 @@
 ess'));%0A
-%09%09
 %09return 
@@ -1067,21 +1067,20 @@
 gress);%0A
-%09%09
 %7D;%0A
+%0A
 Connecto
@@ -1109,18 +1109,16 @@
 on () %7B%0A
-%09%09
 %09updateT
@@ -1129,18 +1129,16 @@
 Info();%0A
-%09%09
 %09return 
@@ -1173,21 +1173,20 @@
 TION%5D);%0A
-%09%09
 %7D;%0A
+%0A
 Connecto
@@ -1281,13 +1281,11 @@
 ying');%0A
-%09%09
 %7D;%0A

Fix formatting in VK connector