forked from web-scrobbler/web-scrobbler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tubafm.js
55 lines (47 loc) · 1.4 KB
/
tubafm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Chrome-Last.fm-Scrobbler tuba.fm connector
* 2012 Michal Rumanek <michal.rumanek@gmail.com>
*
* (based on Zvooq.ru connector)
*/
function parseDurationString(timestr) {
if (timestr) {
var m = /(\d+):(\d+)/.exec(timestr);
return parseInt(m[1], 10) * 60 + parseInt(m[2], 10);
}
return 0;
}
$(function() {
var lastTrack = null;
var $r = chrome.extension.sendRequest;
$(window).unload(function() {
chrome.extension.sendRequest({type: 'reset'});
return true;
});
$("#app_song_title\\[0\\]").bind('DOMSubtreeModified', function (e) {
$("#app_time").bind('DOMSubtreeModified', function (e) {
var duration = parseDurationString($(this).text());
if (duration > 0) {
$(this).unbind('DOMSubtreeModified');
var artist = $("#app_artist_name\\[0\\]").text();
var title = $("#app_song_title\\[0\\]").text();
if (lastTrack != (artist + " - " + title)) {
var total = duration;
lastTrack = artist + " - " + title;
$r({type: 'validate', artist: artist, track: title}, function(response) {
if (response != false) {
$r({
type: 'nowPlaying',
artist: response.artist,
track: response.track,
duration: total
});
} else {
$r({type: 'nowPlaying', duration: total});
}
});
}
}
});
});
});