forked from web-scrobbler/web-scrobbler
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
288 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Chrome-Last.fm-Scrobbler 22tracks.com connector by Dunaeva Natalia | ||
* https://github.com/plushsteel | ||
* http://www.lastfm.ru/user/SlaveOfBeauty | ||
* | ||
* (based on Pandora.com connector by Jordan Perr) | ||
* | ||
*/ | ||
|
||
/********* Configuration: ***********/ | ||
|
||
// changes to the DOM in this container will trigger an update. | ||
LFM_WATCHED_CONTAINER = ".player"; | ||
|
||
// function that returns title of current song | ||
function LFM_TRACK_TITLE() { | ||
res = $(LFM_WATCHED_CONTAINER+" span.title:first").text(); | ||
res = res.split(' - '); | ||
res = res[1]; | ||
return res; | ||
} | ||
|
||
// function that returns artist of current song | ||
function LFM_TRACK_ARTIST() { | ||
res = $(LFM_WATCHED_CONTAINER+" span.title:first").text(); | ||
res = res.split(' - '); | ||
res = res[0]; | ||
return res; | ||
} | ||
|
||
// function that returns duration of current song in seconds | ||
// called at begining of song | ||
function LFM_TRACK_DURATION() { | ||
durationArr = $(LFM_WATCHED_CONTAINER+" .remaining").text().split(":"); | ||
return parseInt(durationArr[0])*60 + parseInt(durationArr[1]); | ||
} | ||
|
||
|
||
/********* Connector: ***********/ | ||
|
||
var LFM_lastTrack = ""; | ||
var LFM_isWaiting = 0; | ||
|
||
function LFM_updateNowPlaying(){ | ||
|
||
// Acquire data from page | ||
title = LFM_TRACK_TITLE(); | ||
artist = LFM_TRACK_ARTIST(); | ||
duration = LFM_TRACK_DURATION(); | ||
// console.log(title,artist,duration); | ||
newTrack = title + " " + artist; | ||
// Update scrobbler if necessary | ||
if (newTrack != "" && newTrack != LFM_lastTrack){ | ||
if (duration == 0) { | ||
// Nasty workaround for delayed duration visiblity with skipped tracks. | ||
setTimeout(LFM_updateNowPlaying, 5000); | ||
return 0; | ||
} | ||
//console.log("submitting a now playing request. artist: "+artist+", title: "+title+", duration: "+duration); | ||
LFM_lastTrack = newTrack; | ||
chrome.extension.sendRequest({type: 'validate', artist: artist, track: title}, function(response) { | ||
if (response != false) { | ||
chrome.extension.sendRequest({type: 'nowPlaying', artist: artist, track: title, duration: duration}); | ||
} else { // on failure send nowPlaying 'unknown song' | ||
chrome.extension.sendRequest({type: 'nowPlaying', duration: duration}); | ||
} | ||
}); | ||
} | ||
LFM_isWaiting = 0; | ||
} | ||
|
||
// Run at startup | ||
$(function(){ | ||
//console.log("22tracks module starting up"); | ||
|
||
$(LFM_WATCHED_CONTAINER).live('DOMSubtreeModified', function(e) { | ||
//console.log("Live watcher called"); | ||
if ($(LFM_WATCHED_CONTAINER).length > 0) { | ||
if(LFM_isWaiting == 0){ | ||
LFM_isWaiting = 1; | ||
setTimeout(LFM_updateNowPlaying, 10000); | ||
} | ||
return; | ||
} | ||
}); | ||
|
||
$(window).unload(function() { | ||
chrome.extension.sendRequest({type: 'reset'}); | ||
return true; | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Chrome-Last.fm-Scrobbler Megalyrics.ru connector by Dunaeva Natalia | ||
* https://github.com/plushsteel | ||
* http://www.lastfm.ru/user/SlaveOfBeauty | ||
* | ||
* (based on Pandora.com connector by Jordan Perr) | ||
* | ||
*/ | ||
|
||
/********* Configuration: ***********/ | ||
|
||
// changes to the DOM in this container will trigger an update. | ||
LFM_WATCHED_CONTAINER = "#ui_title_bar"; | ||
|
||
// function that returns title of current song | ||
function LFM_TRACK_TITLE() { | ||
link = $("#ui_song_title").html(); | ||
res = link.replace(/<b>.*<\/b> - /g,''); | ||
return res; | ||
} | ||
|
||
// function that returns artist of current song | ||
function LFM_TRACK_ARTIST() { | ||
res = $("#ui_song_title b").text(); | ||
return res; | ||
} | ||
|
||
// function that returns duration of current song in seconds | ||
// called at begining of song | ||
function LFM_TRACK_DURATION() { | ||
durationArr = $("#ui_time").text().split('/')[1].split(":"); | ||
return parseInt(durationArr[0])*60 + parseInt(durationArr[1]); | ||
} | ||
|
||
|
||
/********* Connector: ***********/ | ||
|
||
var LFM_lastTrack = ""; | ||
var LFM_isWaiting = 0; | ||
|
||
function LFM_updateNowPlaying(){ | ||
|
||
// Acquire data from page | ||
title = LFM_TRACK_TITLE(); | ||
artist = LFM_TRACK_ARTIST(); | ||
duration = LFM_TRACK_DURATION(); | ||
//console.log(title,artist,duration); | ||
newTrack = title + " " + artist; | ||
// Update scrobbler if necessary | ||
if (newTrack != "" && newTrack != LFM_lastTrack){ | ||
if (duration == 0) { | ||
// Nasty workaround for delayed duration visiblity with skipped tracks. | ||
setTimeout(LFM_updateNowPlaying, 5000); | ||
return 0; | ||
} | ||
//console.log("submitting a now playing request. artist: "+artist+", title: "+title+", duration: "+duration); | ||
LFM_lastTrack = newTrack; | ||
chrome.extension.sendRequest({type: 'validate', artist: artist, track: title}, function(response) { | ||
if (response != false) { | ||
chrome.extension.sendRequest({type: 'nowPlaying', artist: artist, track: title, duration: duration}); | ||
} else { // on failure send nowPlaying 'unknown song' | ||
chrome.extension.sendRequest({type: 'nowPlaying', duration: duration}); | ||
} | ||
}); | ||
} | ||
LFM_isWaiting = 0; | ||
} | ||
|
||
// Run at startup | ||
$(function(){ | ||
//console.log("Megalyrics module starting up"); | ||
$(LFM_WATCHED_CONTAINER).live('DOMSubtreeModified', function(e) { | ||
//console.log("Live watcher called"); | ||
if ($(LFM_WATCHED_CONTAINER).length > 0) { | ||
if(LFM_isWaiting == 0){ | ||
LFM_isWaiting = 1; | ||
setTimeout(LFM_updateNowPlaying, 10000); | ||
} | ||
return; | ||
} | ||
}); | ||
|
||
$(window).unload(function() { | ||
chrome.extension.sendRequest({type: 'reset'}); | ||
return true; | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Chrome-Last.fm-Scrobbler Weborama.fm connector by Dunaeva Natalia | ||
* https://github.com/plushsteel | ||
* http://www.lastfm.ru/user/SlaveOfBeauty | ||
* | ||
* (based on Pandora.com connector by Jordan Perr) | ||
* | ||
*/ | ||
|
||
/********* Configuration: ***********/ | ||
|
||
// changes to the DOM in this container will trigger an update. | ||
LFM_WATCHED_CONTAINER = "#progressBarText"; | ||
|
||
// function that returns title of current song | ||
function LFM_TRACK_TITLE() { | ||
link = $("#song a").attr('href'); | ||
link = link.split('/'); | ||
res = link[6].replace(/_/g,' '); | ||
res = decodeURIComponent(res); | ||
return res; | ||
} | ||
|
||
// function that returns artist of current song | ||
function LFM_TRACK_ARTIST() { | ||
link = $("#song a").attr('href'); | ||
link = link.split('/'); | ||
res = link[4].replace(/_/g,' '); | ||
res = decodeURIComponent(res); | ||
return res; | ||
} | ||
|
||
// function that returns duration of current song in seconds | ||
// called at begining of song | ||
function LFM_TRACK_DURATION() { | ||
durationArr = $("#timeRemaind").text().substring(1).split(":"); | ||
return parseInt(durationArr[0])*60 + parseInt(durationArr[1]); | ||
} | ||
|
||
|
||
/********* Connector: ***********/ | ||
|
||
var LFM_lastTrack = ""; | ||
var LFM_isWaiting = 0; | ||
|
||
function LFM_updateNowPlaying(){ | ||
|
||
// Acquire data from page | ||
title = LFM_TRACK_TITLE(); | ||
artist = LFM_TRACK_ARTIST(); | ||
duration = LFM_TRACK_DURATION(); | ||
newTrack = title + " " + artist; | ||
// Update scrobbler if necessary | ||
if (newTrack != "" && newTrack != LFM_lastTrack){ | ||
if (duration == 0) { | ||
// Nasty workaround for delayed duration visiblity with skipped tracks. | ||
setTimeout(LFM_updateNowPlaying, 5000); | ||
return 0; | ||
} | ||
//console.log("submitting a now playing request. artist: "+artist+", title: "+title+", duration: "+duration); | ||
LFM_lastTrack = newTrack; | ||
chrome.extension.sendRequest({type: 'validate', artist: artist, track: title}, function(response) { | ||
if (response != false) { | ||
chrome.extension.sendRequest({type: 'nowPlaying', artist: artist, track: title, duration: duration}); | ||
} else { // on failure send nowPlaying 'unknown song' | ||
chrome.extension.sendRequest({type: 'nowPlaying', duration: duration}); | ||
} | ||
}); | ||
} | ||
LFM_isWaiting = 0; | ||
} | ||
|
||
// Run at startup | ||
$(function(){ | ||
//console.log("Weborama module starting up"); | ||
|
||
$(LFM_WATCHED_CONTAINER).live('DOMSubtreeModified', function(e) { | ||
//console.log("Live watcher called"); | ||
if ($(LFM_WATCHED_CONTAINER).length > 0) { | ||
if(LFM_isWaiting == 0){ | ||
LFM_isWaiting = 1; | ||
setTimeout(LFM_updateNowPlaying, 10000); | ||
} | ||
return; | ||
} | ||
}); | ||
|
||
$(window).unload(function() { | ||
chrome.extension.sendRequest({type: 'reset'}); | ||
return true; | ||
}); | ||
}); | ||
|