'use strict';

/* global Connector */

/*	What a y2k site design, seriously. Oh wait, it's VAPORWAVE!
	That explains everything.
*/
Connector.playerSelector = '#main > center';

/**
 * remove zero width characters & trim
 * @param  {string} text to clean up
 * @return {string} cleaned up text
 */
function cleanText(input) {
	if (input === null) {
		return input;
	}
	input = input.replace('´', '\'');
	input = input.replace('`', '\'');
	return input.replace(/[\u200B-\u200D\uFEFF]/g, '').trim();
}

// dreamfm.biz hack
function getDreamPlayer() {
	var players = $('#player > *, #player2 > *');
	var player = players.filter(':visible').first();
	return player || null;
}

Connector.getArtist = function() {
	var artist = getDreamPlayer().find('#tracka').text() ||
				null;
	return cleanText(artist);
};

Connector.getTrack = function() {
	var track = getDreamPlayer().find('#tracktitle').text() ||
				null;
	return cleanText(track);
};

Connector.getAlbum = function () {
	var album = getDreamPlayer().find('#album').text() ||
				null;
	return cleanText(album);
};

Connector.isPlaying = function() {
	var e = getDreamPlayer().find('button[title="Play"]');
	return (e === null || !e.is(':visible'));
};

Connector.getCurrentTime = function() {
	var audio = getDreamPlayer().find('audio')[0];
	if (audio === null) {
		return null;
	}
	return audio.currentTime;
}

Connector.getTrackArt = function() {
	return $('#imgcover').prop('src') ||
		null;
};

Connector.getDuration = function () {
	var audio = getDreamPlayer().find('audio')[0];
	if (audio === null) {
		return null;
	}
	return Math.round(audio.duration);
};

/** Returns a unique identifier of current track.
 *  @returns {String|null} */
Connector.getUniqueID = function () {
	var audio = getDreamPlayer().find('audio').first();
	var match = /&id=(\d+)&/.exec(audio.attr('src'));
	if (match) {
		return match[1];
	}
	return null;
};

@@ -36,101 +36,8 @@
 */%0A%0A
-/*%09What a y2k site design, seriously. Oh wait, it's VAPORWAVE!%0A%09That explains everything.%0A*/%0A
 Conn
@@ -65,19 +65,12 @@
 = '#
-main %3E cent
+play
 er';
@@ -266,307 +266,65 @@
 %09%7D%0A%09
-input = input.replace('%C2%B4', '%5C'');%0A%09input = input.replace('%60', '%5C'');%0A%09return input.replace(/%5B%5Cu200B-%5Cu200D%5CuFEFF%5D/g, '').trim();%0A%7D%0A%0A// dreamfm.biz hack%0Afunction getDreamPlayer() %7B%0A%09var players = $('#player %3E *, #player2 %3E *');%0A%09var player = players.filter(':visible').first();%0A%09return player %7C%7C null
+return input.replace(/%5B%5Cu200B-%5Cu200D%5CuFEFF%5D/g, '').trim()
 ;%0A%7D%0A
@@ -373,37 +373,17 @@
 rtist = 
-getDreamPlayer().find
+$
 ('#track
@@ -484,37 +484,17 @@
 track = 
-getDreamPlayer().find
+$
 ('#track
@@ -599,37 +599,17 @@
 album = 
-getDreamPlayer().find
+$
 ('#album
@@ -709,51 +709,28 @@
 e = 
-getDreamPlayer().find('button%5Btitle=%22P
+$('.play-pause .p
 lay
-%22%5D
 ');%0A
@@ -790,12 +790,9 @@
 tor.
-getC
+c
 urre
@@ -801,141 +801,29 @@
 Time
- = function() %7B%0A%09var audio = getDreamPlayer().find('audio')%5B0%5D;%0A%09if (audio === null) %7B%0A%09%09return null;%0A%09%7D%0A%09return audio.currentTime;%0A%7D
+Selector = '.played';
 %0A%0ACo
@@ -895,18 +895,8 @@
 rc')
- %7C%7C%0A%09%09null
 ;%0A%7D;
@@ -939,97 +939,8 @@
 ) %7B%0A
-%09var audio = getDreamPlayer().find('audio')%5B0%5D;%0A%09if (audio === null) %7B%0A%09%09return null;%0A%09%7D%0A
 %09ret
@@ -954,21 +954,29 @@
 h.round(
+$('
 audio
+')%5B0%5D
 .duratio
@@ -1105,61 +1105,8 @@
 ) %7B%0A
-%09var audio = getDreamPlayer().find('audio').first();%0A
 %09var
@@ -1132,21 +1132,34 @@
 &/.exec(
+$('
 audio
+').first()
 .attr('s

Revert "Fix dreamfm.biz"