Skip to content

Commit

Permalink
- Performance: badgeTitle works like the new badgeIcon system;
Browse files Browse the repository at this point in the history
  • Loading branch information
rentalhost committed Oct 1, 2011
1 parent c3d2fca commit 61347e8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
34 changes: 20 additions & 14 deletions javascript/background.js
Expand Up @@ -17,6 +17,9 @@ function init () {
// If null, will render the new icon
var last19;

// Performance: save the last title to avoid use Chrome API
var lastTitle;

// Performance: preload the play-icon
var playImage = new Image();
playImage.src = ICONS['playing'];
Expand Down Expand Up @@ -60,6 +63,22 @@ function init () {
});
}
});

// Update badgeTitle - the song name, if avaiable
userAction('getCurrentSongData', null, function(songName, songArtist){
// If playlist is empty
if(songName === 'UNAVAILABLE'){
lastTitle = null;
return resetTitle();
}

// Else, set the new title info
var new_lastTitle = songName + ' - ' + songArtist;
if(new_lastTitle !== lastTitle){
lastTitle = new_lastTitle;
chrome.browserAction.setTitle({title: new_lastTitle});
}
});
}, 1000);
}

Expand All @@ -72,11 +91,7 @@ function setIcon (icon) {
}

function resetTitle () {
setTitle('Grooveshark Control');
}

function setTitle (title) {
chrome.browserAction.setTitle({title: title});
chrome.browserAction.setTitle({title: 'Grooveshark Control'});
}

function injectGrooveshark () {
Expand All @@ -89,20 +104,11 @@ function injectGrooveshark () {
chrome.extension.onRequest.addListener(
function (request, sender, sendResponse) {
if (request.command === 'updateData') {
setTitleByRequst(request);
setIndexOfActiveSongByRequest(request);
}
}
);

function setTitleByRequst (request) {
if (request.isSomePlaylist) {
setTitle(request.currentSong.ArtistName + ' - ' + request.currentSong.SongName);
} else {
resetTitle();
}
}

function setIndexOfActiveSongByRequest (request) {
if (request.isSomePlaylist) {
if (
Expand Down
16 changes: 16 additions & 0 deletions javascript/contentscript.js
Expand Up @@ -163,6 +163,22 @@ var GCInjector = new function () {
return callback(100 * playbackStatus.position / playbackStatus.duration);
}

// Get current song and artist name basically to fill badgeTitle
this.getCurrentSongData = function(callback){
// Does nothing, if GS yet is not defined
if (this.GS === false) {
return;
}

// If not have nothing on playlist, send resetTitle command
if (this.isSomePlaylist() === false) {
return callback('UNAVAILABLE');
}

// Else, send song and artist name by callback
return callback(this.GS.player.currentSong.SongName, this.GS.player.currentSong.ArtistName);
}

// Get Data
this.getData = function () {
function parseSongItem (item) {
Expand Down

0 comments on commit 61347e8

Please sign in to comment.