forked from web-scrobbler/web-scrobbler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
myspace.js
62 lines (53 loc) · 1.48 KB
/
myspace.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
56
57
58
59
60
61
62
/*
* Chrome-Last.fm-Scrobbler MySpace.com Connector by Yasin Okumus
* http://www.yasinokumus.com
*/
var durationPart = ".duration";
var trackPart = ".songTitle";
var artistPart = ".bandName";
$(function(){
// bind page unload function to discard current "now listening"
cancel();
});
$(document).ready(function(){
console.log('DOCUMENT READY');
// show disabled icon
chrome.extension.sendRequest({type: 'reportDisabled'}, function(response){
console.log(response);
});
console.log('REQUEST SENT');
/* reenable after fix
$(durationPart).bind('DOMSubtreeModified',function(e){
var duration = parseDuration($(durationPart).text());
// if track list deleted
if(duration == 0){
cancel();
}
else if(duration > 90){
var artist = $(artistPart).text();
var track = $(trackPart).text();
chrome.extension.sendRequest({type: 'validate', artist: artist, track: track}, function(response) {
if (response != false){
chrome.extension.sendRequest({type: 'nowPlaying', artist: artist, track: track, duration: duration});
}
});
}
});
*/
});
function parseDuration(match){
try{
mins = match.substring(0, match.indexOf(':'));
seconds = match.substring(match.indexOf(':')+1);
return parseInt(mins*60) + parseInt(seconds);
}catch(err){
return 0;
}
}
function cancel(){
$(window).unload(function() {
// reset the background scrobbler song data
chrome.extension.sendRequest({type: 'reset'});
return true;
});
}