forked from web-scrobbler/web-scrobbler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virginradiotr.js
130 lines (122 loc) · 2.27 KB
/
virginradiotr.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
*
* Chrome-Last.fm-Scrobbler
* http://www.virginradioturkiye.com/live
* http://live.radioeksen.com/live
*
*
*
* Connector by Salim KAYABAŞI
* http://www.salimkayabasi.com
* to debug change its' status to 'true'
*/
var artist = '';
var track = '';
var isNewSong = true;
var playingSong = '#playingSong';
var debug = false;
$(function(){
process();
$(playingSong).bind('DOMSubtreeModified',function(e){
process();
});
// bind page unload function to discard current "now listening"
$(window).unload(function() {
// reset the background scrobbler song data
chrome.extension.sendRequest({type: 'reset'});
return true;
});
});
function process()
{
if(document.getElementById('playPauseButton').innerText != 'Başlat/Duraklat')
{
if(debug)
{
console.log('not playing');
}
return;
}
else{
if(debug)
{
console.log('playing now');
}
}
if(parseTrack())
{
try{
if(isNewSong)
{
chrome.extension.sendRequest({type: 'validate', artist: artist, track: track}, function(response) {
if (response != false){
chrome.extension.sendRequest({type: 'nowPlaying', artist: artist, track: track, duration: '245'});
if(debug)
{
console.log('--scrobbling--')
}
}
else
{
if(debug)
{
console.log(response);
}
}
});
}
}
catch(e){
if(debug)
{
console.log(e);
}
}
}
};
function parseTrack()
{
var song = document.getElementById('playingSong').innerText.trim();
if(song == '')
{
if(debug)
{
console.log('NotFound: Song');
}
return false;
}
if(song.indexOf('Program / Tanıtım / Reklam') != -1)
{
if(debug)
{
console.log('advertisement will not send to Last.fm');
}
return false;
}
if(song.indexOf('Sonraki Şarkı') != -1)
{
song = song.substring(0,song.indexOf('Sonraki Şarkı'));
}
separation = song.lastIndexOf(' - ');
var TMPtrack = song.substring(0, separation).trim();
var TMPartist = song.substring(separation+3).trim();
if(artist != TMPartist && track != TMPtrack)
{
isNewSong = true;
artist = TMPartist;
track = TMPtrack;
if(debug)
{
console.log('NEW SONG ' +track +' from '+artist);
}
}
else
{
isNewSong = false;
if(debug)
{
console.log('SAME SONG ' +track +' from '+artist);
}
}
return true;
}