forked from web-scrobbler/web-scrobbler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zvooq.js
49 lines (40 loc) · 1.56 KB
/
zvooq.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
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() {
// reset the background scrobbler song data
chrome.extension.sendRequest({type: 'reset'});
return true;
});
$(".topPanel_playerPlayback_leave").bind('DOMSubtreeModified', function (e) {
var duration = parseDurationString($(".topPanel_playerPlayback_leave").text());
if (duration > 0) {
var m = /(.*)\s+—\s+(.*)/.exec($(".topPanel_playerPlayback_playered_name").text());
var artist = m[1];
var title = m[2];
if (lastTrack != $(".topPanel_playerPlayback_playered_name").text()) {
var total = duration;
lastTrack = $(".topPanel_playerPlayback_playered_name").text();
$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});
}
});
}
}
});
});