Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
david-sabata committed Aug 23, 2012
2 parents fe988d8 + 9720741 commit f5465e8
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 1 deletion.
92 changes: 92 additions & 0 deletions 22tracks.js
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;
});
});

16 changes: 15 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Last.fm Scrobbler",
"version": "1.9",
"version": "1.9.1",

"description": "Scrobble music all around the web!",
"icons": {
Expand Down Expand Up @@ -117,6 +117,20 @@
{
"matches": ["*://zvooq.ru/*"],
"js": ["jquery-1.6.1.min.js", "zvooq.js"]
},
{
"matches": ["*://www.weborama.fm/*"],
"all_frames": true,
"js": ["jquery-1.6.1.min.js", "weborama.js"]
},
{
"matches": ["*://22tracks.com/*"],
"js": ["jquery-1.6.1.min.js", "22tracks.js"]
},
{
"matches": ["*://megalyrics.ru/*"],
"all_frames": true,
"js": ["jquery-1.6.1.min.js", "megalyrics.js"]
}


Expand Down
88 changes: 88 additions & 0 deletions megalyrics.js
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;
});
});

93 changes: 93 additions & 0 deletions weborama.js
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;
});
});

0 comments on commit f5465e8

Please sign in to comment.