diff --git a/connectors/pakartot.js b/connectors/pakartot.js new file mode 100644 index 0000000000..48e767798c --- /dev/null +++ b/connectors/pakartot.js @@ -0,0 +1,103 @@ +/* + * Chrome-Last.fm-Scrobbler pakartot.lt Connector + * + * Juozas Masiulis --- http://www.euphorbium.lt --- + * juozas.masiulis[at]euphorbium[dot]lt + * + */ + +/********* Configuration: ***********/ + +// changes to the DOM in this container will trigger an update. +LFM_WATCHED_CONTAINER = "div.jp-info"; + +// function that returns title of current song +function LFM_TRACK_TITLE() { + return $(".jp-player-title>a").text(); +} + +// function that returns artist of current song +function LFM_TRACK_ARTIST() { + return $(".jp-player-artist>a").text(); +} + +// function that returns album of current song +function LFM_TRACK_ALBUM() { + return $("a.playerBarAlbum").text(); +} + +// function that returns duration of current song in seconds +// called at begining of song +function LFM_TRACK_DURATION() { + durationArr = $("div.jp-current-time").html().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(); + 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.runtime.sendMessage({type: 'validate', artist: artist, track: title}, function(response) { + if (response != false) { + chrome.runtime.sendMessage({type: 'nowPlaying', artist: artist, track: title, duration: duration}); + } else { // on failure send nowPlaying 'unknown song' + chrome.runtime.sendMessage({type: 'nowPlaying', duration: duration}); + } + }); + } + LFM_isWaiting = 0; +} + +// Run at startup +$(function(){ + console.log("pakartot 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.runtime.sendMessage({type: 'reset'}); + return true; + }); +}); + + +/** + * Listen for requests from scrobbler.js + */ +chrome.runtime.onMessage.addListener( + function(request, sender, sendResponse) { + switch(request.type) { + + // background calls this to see if the script is already injected + case 'ping': + sendResponse(true); + break; + } + } +); diff --git a/core/connectors.js b/core/connectors.js index c8e711f511..9fbb2f0f5b 100644 --- a/core/connectors.js +++ b/core/connectors.js @@ -53,19 +53,19 @@ define(function() { js: ['connectors/61.js'] }, + //{ + // label: 'Google Play Music', + // matches: ['*://play.google.com/music/*', '*://play-music.sandbox.google.com/music/*'], + // js: ['connectors/googlemusic.js'] + //}, + { label: 'Google Play Music', matches: ['*://play.google.com/music/*'], - js: ['connectors/googlemusic.js'] + js: ['connectors/v2/googlemusic.js'], + version: 2 }, -// { -// label: 'Google Play Music', -// matches: ['*://play.google.com/music/*'], -// js: ['connectors/v2/googlemusic.js'], -// version: 2 -// }, - { label: 'MySpace', matches: ['*://myspace.com/*'], @@ -104,7 +104,7 @@ define(function() { { label: 'Bandcamp', - matches: ['*://*.bandcamp.com/*'], + matches: ['*://*.bandcamp.com/*', '*://bandcamp.com/discover'], js: ['connectors/bandcamp.js'] }, @@ -120,6 +120,12 @@ define(function() { js: ['connectors/pandora.js'] }, + { + label: 'pakartot', + matches: ['*://www.pakartot.lt/*'], + js: ['connectors/pakartot.js'] + }, + { label: 'Deezer', matches: ['*://www.deezer.com/*'], @@ -134,7 +140,7 @@ define(function() { { label: 'Amazon', - matches: ['*://www.amazon.com/gp/dmusic/*/player*', '*://www.amazon.de/gp/dmusic/*/player*', '*://www.amazon.es/gp/dmusic/*/player*', '*://www.amazon.co.uk/gp/dmusic/*/player*'], + matches: ['*://www.amazon.com/gp/dmusic/cloudplayer/*', '*://www.amazon.de/gp/dmusic/cloudplayer/*', '*://www.amazon.es/gp/dmusic/cloudplayer/*', '*://www.amazon.co.uk/gp/dmusic/cloudplayer/*'], js: ['connectors/amazon.js'] }, @@ -208,7 +214,7 @@ define(function() { { label: 'Plug.dj', - matches: ['http://plug.dj/*'], + matches: ['*://plug.dj/*'], js: ['connectors/plugdj.js'] }, @@ -421,6 +427,30 @@ define(function() { label: 'Soundozer', matches: ['*://soundozer.com/*'], js: ['connectors/soundozer.js'] + }, + + { + label: '163 Music', + matches: ['*://music.163.com/*'], + js: ['connectors/163music.js'] + }, + + { + label: 'blinkboxMusic', + matches: ['*://www.blinkboxmusic.com/*'], + js: ['connectors/blinkboxmusic.js'] + }, + + { + label: 'luooMusic', + matches: ['*://www.luoo.net/*'], + js: ['connectors/luoo.js'] + }, + + { + label: 'ambientsleepingpill', + matches: ['*://*.ambientsleepingpill.com/'], + js: ['connectors/ambientsleepingpill.js'] } ]; });