Skip to content
Browse files

merge, preview.grooveshark.com

  • Loading branch information...
1 parent fd41eee commit e460ba91650b435eece15727ee2e7775cb442155 @horejsek horejsek committed Oct 16, 2011
Showing with 374 additions and 396 deletions.
  1. +77 −84 javascript/background.js
  2. +106 −105 javascript/contentscript.js
  3. +77 −80 javascript/groovesharkControl.js
  4. +48 −54 javascript/notification.js
  5. +61 −69 javascript/popup.js
  6. +4 −3 manifest.json
  7. +1 −1 views/popup.html
View
161 javascript/background.js
@@ -13,93 +13,86 @@ function init () {
periodicDataGetter(callbackIfGroovesharkIsNotOpen=resetIcon);
injectGrooveshark();
- // Performance: store last 19 percentage status
- // If null, will render the new icon
- var last19;
+ // Performance: store last 19 percentage status
+ // If null, will render the new icon
+ var last19;
- // Performance: save the last title to avoid use Chrome API
- var lastTitle;
+ // 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'];
+ // Performance: preload the play-icon
+ var playImage = new Image();
+ playImage.src = ICONS['playing'];
// Start the data collector system
- setInterval(function(){
- // Update the badgeIcon baseed on player percentage
- // UNAVAILABLE, STOPPED or percentage (float)
- userAction('getCurrentPercentage', null, function(percentage){
- // If playlist is empty
- if (percentage === 'UNAVAILABLE') {
- last19 = null;
- return resetIcon();
- }
-
- // If player is paused
- if (percentage === 'STOPPED') {
- last19 = null;
- return setIcon(ICONS['pause']);;
- }
-
- // Else, calcule the new last19
- // If is different of the old last19, render the new icon
- var new_last19 = Math.round(percentage / (100 / 19));
- if (new_last19 !== last19) {
- last19 = new_last19;
-
- var canvas = document.getElementById('canvas');
- var context = canvas.getContext('2d');
-
- context.clearRect(0, 0, 19, 19);
- context.drawImage(playImage, 0, 0);
-
- context.fillStyle = '#CCC';
- context.fillRect(0, 17, 19, 19);
-
- context.fillStyle = '#000';
- context.fillRect(0, 17, new_last19, 19);
-
- chrome.browserAction.setIcon({
- imageData: context.getImageData(0, 0, 19, 19)
- });
- }
- });
-
- // 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});
- }
- });
-
- // Configure the active queue song id, and open the notification bar
- userAction('getQueueSongId', null, function(queueSongId){
- // If playlist is empty, set song queue ID to -1
- if (queueSongId === 'UNAVAILABLE') {
- activeQueueSongID = -1;
- return;
- }
-
- // Auto-show notification system
- if (queueSongId != -1
- && activeQueueSongID != -1
- && activeQueueSongID != queueSongId
- && last19 < 1) {
- showNotification();
- }
-
- // Set the active queue song ID
- activeQueueSongID = queueSongId;
- });
+ setInterval(function () {
+ // Update the badgeIcon baseed on player percentage
+ // UNAVAILABLE, STOPPED or percentage (float)
+ userAction('getCurrentPercentage', null, function(percentage){
+ if (percentage === 'UNAVAILABLE') {
+ last19 = null;
+ return resetIcon();
+ }
+
+ if (percentage === 'STOPPED') {
+ last19 = null;
+ return setIcon(ICONS['pause']);;
+ }
+
+ // If is different of the old last19, render the new icon
+ var new_last19 = Math.round(percentage / (100 / 19));
+ if (new_last19 !== last19) {
+ last19 = new_last19;
+
+ var canvas = document.getElementById('canvas');
+ var context = canvas.getContext('2d');
+
+ context.clearRect(0, 0, 19, 19);
+ context.drawImage(playImage, 0, 0);
+
+ context.fillStyle = '#CCC';
+ context.fillRect(0, 17, 19, 19);
+
+ context.fillStyle = '#000';
+ context.fillRect(0, 17, new_last19, 19);
+
+ chrome.browserAction.setIcon({
+ imageData: context.getImageData(0, 0, 19, 19)
+ });
+ }
+ });
+
+ // Update badgeTitle - the song name, if avaiable
+ userAction('getCurrentSongData', null, function (songName, songArtist) {
+ if (songName === 'UNAVAILABLE') {
+ lastTitle = null;
+ return resetTitle();
+ }
+
+ var new_lastTitle = songName + ' - ' + songArtist;
+ if (new_lastTitle !== lastTitle) {
+ lastTitle = new_lastTitle;
+ chrome.browserAction.setTitle({title: new_lastTitle});
+ }
+ });
+
+ // Configure the active queue song id, and open the notification bar
+ userAction('getQueueSongId', null, function(queueSongId){
+ if (queueSongId === 'UNAVAILABLE') {
+ activeQueueSongID = -1;
+ return;
+ }
+
+ // Auto-show notification system
+ if (queueSongId != -1
+ && activeQueueSongID != -1
+ && activeQueueSongID != queueSongId
+ && last19 < 1) {
+ showNotification();
+ }
+
+ activeQueueSongID = queueSongId;
+ });
}, 1000);
}
@@ -112,7 +105,7 @@ function setIcon (icon) {
}
function resetTitle () {
- chrome.browserAction.setTitle({title: 'Grooveshark Control'});
+ chrome.browserAction.setTitle({title: 'Grooveshark Control'});
}
function injectGrooveshark () {
View
211 javascript/contentscript.js
@@ -3,6 +3,21 @@ var GCInjector = new function () {
var self = this;
this.GS = false;
+ window.onload = function () {
+ self.GS = this.GS;
+ }
+
+ // Make a call to an internal command
+ this.call = function (command, args, callback) {
+ // Ignore the call if GS not is ready
+ if (self.GS === false || self.GS === undefined) {
+ return;
+ }
+
+ args.push(callback);
+ self[command].apply(self, args);
+ }
+
// Music controller
this.playSong = function () {
this.GS.player.playSong();
@@ -41,7 +56,7 @@ var GCInjector = new function () {
}
this.toggleShuffle = function () {
- $("#player_shuffle").click();
+ $('#player_shuffle').click();
}
// Crossfade
@@ -50,7 +65,7 @@ var GCInjector = new function () {
}
this.toggleCrossfade = function () {
- $("#player_crossfade").click();
+ $('#player_crossfade').click();
}
// Loop
@@ -59,7 +74,7 @@ var GCInjector = new function () {
}
this.toggleLoop = function () {
- $("#player_loop").click();
+ $('#player_loop').click();
}
// Library
@@ -72,7 +87,7 @@ var GCInjector = new function () {
}
this.toggleLibrary = function () {
- if (!$("#playerDetails_nowPlaying a.add").hasClass("selected")) {
+ if (!$('#playerDetails_nowPlaying a.add').hasClass('selected')) {
this.GS.user.addToLibrary(this.GS.player.currentSong.SongID);
} else {
this.GS.user.removeFromLibrary(this.GS.player.currentSong.SongID);
@@ -89,7 +104,7 @@ var GCInjector = new function () {
}
this.toggleFavorite = function () {
- if (!$("#playerDetails_nowPlaying a.favorite").hasClass("selected")) {
+ if (!$('#playerDetails_nowPlaying a.favorite').hasClass('selected')) {
this.GS.user.addToSongFavorites(this.GS.player.currentSong.SongID);
} else {
this.GS.user.removeFromSongFavorites(this.GS.player.currentSong.SongID);
@@ -98,7 +113,7 @@ var GCInjector = new function () {
// Smile
this.isSmile = function () {
- return $("#queue_list li.queue-item-active div.radio_options a.smile").hasClass("active");
+ return $('#queue_list li.queue-item-active div.radio_options a.smile').hasClass('active');
}
this.toggleSmile = function () {
@@ -107,7 +122,7 @@ var GCInjector = new function () {
// Frown
this.isFrown = function () {
- return $("#queue_list li.queue-item-active div.radio_options a.frown").hasClass("active");
+ return $('#queue_list li.queue-item-active div.radio_options a.frown').hasClass('active');
}
this.toggleFrown = function () {
@@ -116,7 +131,7 @@ var GCInjector = new function () {
// Seek
this.seekTo = function (seekTo) {
- this.GS.player.seekTo((this.GS.player.getPlaybackStatus()["duration"]) / 100 * seekTo);
+ this.GS.player.seekTo((this.GS.player.getPlaybackStatus()['duration']) / 100 * seekTo);
}
// Queue
@@ -125,135 +140,121 @@ var GCInjector = new function () {
}
// Get current percentage info
- this.getCurrentPercentage = function(callback){
- // If not have nothing on playlist, send resetIcon command
- if (this.GS.player.queue.songs.length === 0) {
- return callback('UNAVAILABLE');
- }
+ this.getCurrentPercentage = function (callback) {
+ // If not have nothing on playlist, send resetIcon command
+ if (this.GS.player.queue.songs.length === 0) {
+ return callback('UNAVAILABLE');
+ }
- // If is paused, send pause command
- if (this.GS.player.isPlaying === false) {
- return callback('STOPPED');
- }
+ // If is paused, send pause command
+ if (this.GS.player.isPlaying === false) {
+ return callback('STOPPED');
+ }
- // Else, send current percentage
- var playbackStatus = this.GS.player.getPlaybackStatus();
- return callback(100 * playbackStatus.position / playbackStatus.duration);
+ // Else, send current percentage
+ var playbackStatus = this.GS.player.getPlaybackStatus();
+ return callback(100 * playbackStatus.position / playbackStatus.duration);
}
// Get current song and artist name basically to fill badgeTitle
- this.getCurrentSongData = function(callback){
- // If not have nothing on playlist, send resetTitle command
- if (this.GS.player.queue.songs.length === 0
- || typeof this.GS.player.currentSong === 'undefined') {
- return callback('UNAVAILABLE');
- }
+ this.getCurrentSongData = function (callback) {
+ // If not have nothing on playlist, send resetTitle command
+ if (
+ this.GS.player.queue.songs.length === 0 ||
+ typeof this.GS.player.currentSong === 'undefined'
+ ) {
+ return callback('UNAVAILABLE');
+ }
- // Else, send song and artist name by callback
- return callback(this.GS.player.currentSong.SongName, this.GS.player.currentSong.ArtistName);
+ // Else, send song and artist name by callback
+ return callback(this.GS.player.currentSong.SongName, this.GS.player.currentSong.ArtistName);
}
// Get current queue song ID
- this.getQueueSongId = function(callback){
- // If not have data about currentSong, set data as 'unavailable'
- if (typeof this.GS.player.currentSong === 'undefined') {
- return callback('UNAVAILABLE');
- }
+ this.getQueueSongId = function (callback) {
+ // If not have data about currentSong, set data as 'unavailable'
+ if (typeof this.GS.player.currentSong === 'undefined') {
+ return callback('UNAVAILABLE');
+ }
- // Else, send the queue song ID
- return callback(this.GS.player.queue.activeSong.queueSongID);
+ // Else, send the queue song ID
+ return callback(this.GS.player.queue.activeSong.queueSongID);
}
// Get the player options (suffle, loop and crossfade)
- this.getPlayerOptions = function(callback){
- var playerLoop;
+ this.getPlayerOptions = function (callback) {
+ var playerLoop;
switch (this.GS.player.getRepeat()) {
case 1:
- playerLoop = "one";
- break;
+ playerLoop = 'one';
+ break;
case 2:
- playerLoop = "all";
- break;
+ playerLoop = 'all';
+ break;
default:
- playerLoop = "none";
- break;
+ playerLoop = 'none';
+ break;
}
- return callback(
- this.GS.player.getShuffle(),
- playerLoop,
- this.GS.player.getCrossfadeEnabled()
- );
+ return callback(
+ this.GS.player.getShuffle(),
+ playerLoop,
+ this.GS.player.getCrossfadeEnabled()
+ );
}
// Get now playing data
- this.getNowPlaying = function(callback){
- // If not have data about currentSong, set data as 'unavailable'
- // Using -1 instead of UNAVAILABLE because that the first callback param is string (will confuse it)
- if (typeof this.GS.player.currentSong === 'undefined') {
- return;
- }
-
- var currentSong = this.GS.player.currentSong;
- var playbackStatus = this.GS.player.getPlaybackStatus();
- var queue = this.GS.player.queue;
-
- return callback(
- currentSong.SongName,
- currentSong.ArtistName,
- currentSong.AlbumName,
- currentSong.getImageURL('s'),
- playbackStatus.position,
- playbackStatus.duration,
- $("#playerDetails_nowPlaying a.add").hasClass("selected"),
- $("#playerDetails_nowPlaying a.favorite").hasClass("selected"),
- this.isSmile(),
- this.isFrown(),
- queue.activeSong.index,
- queue.songs.length,
- this.GS.player.isPlaying
- );
+ this.getNowPlaying = function (callback) {
+ // If not have data about currentSong, set data as 'unavailable'
+ // Using -1 instead of UNAVAILABLE because that the first callback param is string (will confuse it)
+ if (typeof this.GS.player.currentSong === 'undefined') {
+ return;
+ }
+
+ var currentSong = this.GS.player.currentSong;
+ var playbackStatus = this.GS.player.getPlaybackStatus();
+ var queue = this.GS.player.queue;
+
+ return callback(
+ currentSong.SongName,
+ currentSong.ArtistName,
+ currentSong.AlbumName,
+ currentSong.getImageURL('s'),
+ playbackStatus.position,
+ playbackStatus.duration,
+ $('#playerDetails_nowPlaying a.add').hasClass('selected'),
+ $('#playerDetails_nowPlaying a.favorite').hasClass('selected'),
+ this.isSmile(),
+ this.isFrown(),
+ queue.activeSong.index,
+ queue.songs.length,
+ this.GS.player.isPlaying
+ );
}
// Get playlist data
- this.getPlaylist = function(callback){
- return callback(
- this.GS.player.queue.songs,
- this.GS.player.queue.activeSong ? this.GS.player.queue.activeSong.index : false,
- this.GS.player.queue.activeSong ? this.GS.player.queue.activeSong.queueSongID : false
- );
+ this.getPlaylist = function (callback) {
+ return callback(
+ this.GS.player.queue.songs,
+ this.GS.player.queue.activeSong ? this.GS.player.queue.activeSong.index : false,
+ this.GS.player.queue.activeSong ? this.GS.player.queue.activeSong.queueSongID : false
+ );
}
// Get radio data
- this.getRadio = function(callback){
- var radioOn = this.GS.player.queue.autoplayEnabled;
- return callback(
- radioOn,
- radioOn ? $("#playerDetails_queue a").text() : false
- );
- }
-
- // Make a call to an internal command
- this.call = function (command, args, callback) {
- // Ignore the call if GS not is ready
- if (self.GS === false) {
- return;
- }
-
- // Run the command
- args.push(callback);
- self[command].apply(self, args);
- }
-
- window.onload = function () {
- self.GS = this.GS;
+ this.getRadio = function (callback) {
+ var radioOn = this.GS.player.queue.autoplayEnabled;
+ return callback(
+ radioOn,
+ radioOn ? $('#playerDetails_queue a').text() : false
+ );
}
}
chrome.extension.onRequest.addListener(function (request, sender, sendMessage) {
if (typeof request.command !== 'undefined') {
- GCInjector.call(request.command, request.args || [], function(){
- sendMessage({args: arguments, argsLength: arguments.length});
- });
+ GCInjector.call(request.command, request.args || [], function () {
+ sendMessage({args: arguments, argsLength: arguments.length});
+ });
}
});
View
157 javascript/groovesharkControl.js
@@ -1,77 +1,67 @@
var isGroovesharkFocused = false;
-/** INIT */
// Init DOM controller system
-function controlInit(autoCallback) {
- var collectData = function(){
- // Control the player options
- userAction('getPlayerOptions', null, function(playerSuffle, playerLoop, playerCrossfade){
- $('#shuffle').attr('class', playerSuffle);
- $('#loop').attr('class', playerLoop);
- $('#crossfade').attr('class', playerCrossfade);
- });
-
- // Control the now playing data
- userAction('getNowPlaying', null, function(songName, artistName, albumName, albumImage,
- playbackPosition, playbackDuration, inLibrary, inFavorite, isSmile, isFrown,
- queueIndex, queueLength, isPlaying){
- // Configure song data
- $('.nowPlaying .song')
- .text(songName)
- .attr('title', songName);
- $('.nowPlaying .artist')
- .text(artistName)
- .attr('title', artistName);
- $('.nowPlaying .album')
- .text(albumName)
- .attr('title', albumName);
-
- // Configure album image
- $('.nowPlaying .image')
- .attr('src', albumImage);
-
- // Configure text time
- $('.nowPlaying .timeElapsed').text(msToHumanTime(playbackPosition));
- $('.nowPlaying .timeDuration').text(msToHumanTime(playbackDuration));
-
- // Configure song preferences
- $('.nowPlaying .library').toggleClass('disable', !inLibrary);
- $('.nowPlaying .favorite').toggleClass('disable', !inFavorite);
- $('.nowPlaying .smile').toggleClass('active', isSmile);
- $('.nowPlaying .frown').toggleClass('active', isFrown);
-
- // Configure queue
- $('.nowPlaying .position .queuePosition').text(queueIndex + 1);
- $('.nowPlaying .position .queueCountSongs').text(queueLength);
-
- // Configure progress bar
- var percentage = Math.round(100 / playbackDuration * playbackPosition);
- $('.progressbar .elapsed').css('width', percentage + '%');
- $('.progressbar').slider('value', percentage);
-
- // Configure player button
- $('#playpause').attr('class', isPlaying ? 'pause' : 'play');
- });
-
- // Collect radio data
- userAction('getRadio', null, function(radioOn, radioStation){
- if (radioStation === false) {
- radioStation = chrome.i18n.getMessage('radioOff')
- }
-
- // Do some DOM changes...
- $('.radio').toggleClass('active', radioOn);
- $('.radio .station').text(radioStation);
- $('.nowPlaying .smile, .nowPlaying .frown').toggleClass('disable', !radioOn);
- });
-
- // Start a new callback collection, if need
- if (autoCallback) {
- autoCallback();
- }
- }
+function controlInit (autoCallback) {
+ var collectData = function () {
+ // Control the player options
+ userAction('getPlayerOptions', null, function (playerSuffle, playerLoop, playerCrossfade) {
+ $('#shuffle').attr('class', playerSuffle);
+ $('#loop').attr('class', playerLoop);
+ $('#crossfade').attr('class', playerCrossfade);
+ });
+
+ // Control the now playing data
+ userAction('getNowPlaying', null, function (songName, artistName, albumName, albumImage,
+ playbackPosition, playbackDuration, inLibrary, inFavorite, isSmile, isFrown,
+ queueIndex, queueLength, isPlaying
+ ) {
+ // Configure song data
+ $('.nowPlaying .song').text(songName).attr('title', songName);
+ $('.nowPlaying .artist').text(artistName).attr('title', artistName);
+ $('.nowPlaying .album').text(albumName).attr('title', albumName);
+ $('.nowPlaying .image').attr('src', albumImage);
+
+ // Configure text time
+ $('.nowPlaying .timeElapsed').text(msToHumanTime(playbackPosition));
+ $('.nowPlaying .timeDuration').text(msToHumanTime(playbackDuration));
+
+ // Configure song preferences
+ $('.nowPlaying .library').toggleClass('disable', !inLibrary);
+ $('.nowPlaying .favorite').toggleClass('disable', !inFavorite);
+ $('.nowPlaying .smile').toggleClass('active', isSmile);
+ $('.nowPlaying .frown').toggleClass('active', isFrown);
+
+ // Configure queue
+ $('.nowPlaying .position .queuePosition').text(queueIndex + 1);
+ $('.nowPlaying .position .queueCountSongs').text(queueLength);
+
+ // Configure progress bar
+ var percentage = Math.round(100 / playbackDuration * playbackPosition);
+ $('.progressbar .elapsed').css('width', percentage + '%');
+ $('.progressbar').slider('value', percentage);
+
+ // Configure player button
+ $('#playpause').attr('class', isPlaying ? 'pause' : 'play');
+ });
+
+ // Collect radio data
+ userAction('getRadio', null, function (radioOn, radioStation) {
+ if (radioStation === false) {
+ radioStation = chrome.i18n.getMessage('radioOff')
+ }
+
+ $('.radio').toggleClass('active', radioOn);
+ $('.radio .station').text(radioStation);
+ $('.nowPlaying .smile, .nowPlaying .frown').toggleClass('disable', !radioOn);
+ });
+
+ // Start a new callback collection, if need
+ if (autoCallback) {
+ autoCallback();
+ }
+ }
// Start the data collector system
setInterval(collectData, 1000);
@@ -97,8 +87,15 @@ function getGroovesharkUrl () {
return 'http://grooveshark.com/';
}
+function getGroovesharkPreviewUrl () {
+ return 'http://preview.grooveshark.com/';
+}
+
function isGroovesharkUrl (url) {
- return !(url.indexOf(getGroovesharkUrl()) != 0)
+ return (
+ url.indexOf(getGroovesharkUrl()) == 0 ||
+ url.indexOf(getGroovesharkPreviewUrl()) == 0
+ )
}
function goToGroovesharkTab () {
@@ -143,17 +140,17 @@ function callWithGroovesharkTab (callback, callbackIfGroovesharkIsNotOpen) {
}
}
- if (typeof callbackIfGroovesharkIsNotOpen !== "undefined") {
+ if (typeof callbackIfGroovesharkIsNotOpen !== 'undefined') {
callbackIfGroovesharkIsNotOpen();
}
});
}
// Close window if tab is closed
function onTabCloseAccept () {
- chrome.tabs.onRemoved.addListener(function(){
- window.close();
- });
+ chrome.tabs.onRemoved.addListener(function () {
+ window.close();
+ });
}
@@ -178,11 +175,11 @@ function userAction (command, args, callback) {
command: command,
args: args
}, function(response){
- if (typeof callback === 'function'){
- response.args.length = response.argsLength;
- callback.apply(this, Array.prototype.slice.call(response.args));
- }
- });
+ if (typeof callback === 'function'){
+ response.args.length = response.argsLength;
+ callback.apply(this, Array.prototype.slice.call(response.args));
+ }
+ });
});
getData();
}
@@ -220,7 +217,7 @@ function _showNotification (stay, view) {
if ((!isNotificationOpen() && !isGroovesharkFocused) || stay) {
var notification = webkitNotifications.createHTMLNotification('../views/'+view+'.html');
- localStorage['_notificationStay'] = stay === true;
+ localStorage['_notificationStay'] = stay === true;
notification.show();
}
}
View
102 javascript/notification.js
@@ -1,71 +1,65 @@
var Notification = new function(){
- this.timer = false;
+ this.timer = false;
- // Init notification system
- this.init = function(){
- // Countdown ONLY if not need "stay"
- if (localStorage.getItem('_notificationStay') !== 'true') {
- this.countDown();
- }
- else {
- localStorage['_notificationStay'] = false;
- this.cancelClose();
- }
+ // Init notification system
+ this.init = function(){
+ // Countdown ONLY if not need "stay"
+ if (localStorage.getItem('_notificationStay') !== 'true') {
+ this.countDown();
+ }
+ else {
+ localStorage['_notificationStay'] = false;
+ this.cancelClose();
+ }
- getData();
- setUpProgressbar();
+ getData();
+ setUpProgressbar();
- $('#liteLine').SetScroller({
- velocity: 50,
- direction: 'horizontal',
- startfrom: 'right',
- loop: 'infinite',
- movetype: 'linear',
- onmouseover: 'pause',
- onmouseout: 'play',
- onstartup: 'play',
- cursor: 'pointer'
- });
+ $('#liteLine').SetScroller({
+ velocity: 50,
+ direction: 'horizontal',
+ startfrom: 'right',
+ loop: 'infinite',
+ movetype: 'linear',
+ onmouseover: 'pause',
+ onmouseout: 'play',
+ onstartup: 'play',
+ cursor: 'pointer'
+ });
- $('#switchToLiteNotification').click(function () {
- showLiteNotification(true);
- setTimeout(window.close, 200);
- });
+ $('#switchToLiteNotification').click(function () {
+ showLiteNotification(true);
+ setTimeout(window.close, 200);
+ });
- $('#switchToFullNotification').click(function () {
- showNotification(true);
- setTimeout(window.close, 200);
- });
+ $('#switchToFullNotification').click(function () {
+ showNotification(true);
+ setTimeout(window.close, 200);
+ });
- // Start the controller
- controlInit();
+ controlInit();
+ onTabCloseAccept();
+ }
- // Close window if tab is closed
- onTabCloseAccept();
- }
-
- // Starts the countdown
- this.countDown = function(){
- console.trace();
- var startTime = (new Date()).getTime();
- this.timer = setInterval(function(){
+ this.countDown = function(){
+ console.trace();
+ var startTime = (new Date()).getTime();
+ this.timer = setInterval(function(){
var percent = Math.min(100, 100 / howLongDisplayNotification() * ( (new Date()).getTime() - startTime ));
$('#countDown').width((100 - percent) + '%');
- // Close if get 100%
if (percent === 100) {
- window.close();
+ window.close();
}
- }, 50);
- }
+ }, 50);
+ }
- // Cancel the close
- this.cancelClose = function(){
- if (this.timer !== false) {
- clearInterval(this.timer);
- }
+ this.cancelClose = function(){
+ if (this.timer !== false) {
+ clearInterval(this.timer);
+ }
- $('#countDown').hide();
- }
+ $('#countDown').hide();
+ }
}
View
130 javascript/popup.js
@@ -1,85 +1,77 @@
var Popup = new function(){
- var activeQueueSongID = -1;
+ var activeQueueSongID = -1;
- // Init popup page
- this.init = function() {
- getData(callbackIfGroovesharkIsNotOpen=createGroovesharkTab);
- setUpProgressbar();
+ // Init popup page
+ this.init = function() {
+ getData(callbackIfGroovesharkIsNotOpen=createGroovesharkTab);
+ setUpProgressbar();
- // Set the last y position on playlist
- var lastYPosition;
+ // Set the last y position on playlist
+ var lastYPosition;
- // Start the controller
- controlInit(function(){
- // Get playlist data
- userAction('getPlaylist', null, function(songs, activeIndex, activeId){
- // Set the active queue song id
- if (activeQueueSongID !== activeId
- && activeIndex !== false) {
- // If is the first open, show body
- if (activeQueueSongID === -1) {
- $('body').css('display', 'block');
- }
+ // Start the controller
+ controlInit(function () {
+ // Get playlist data
+ userAction('getPlaylist', null, function (songs, activeIndex, activeId) {
+ if (activeIndex === false) {
+ goToGroovesharkTab();
+ } else if (activeQueueSongID !== activeId && activeIndex !== false) {
+ // If is the first open, show body
+ if (activeQueueSongID === -1) {
+ $('body').css('display', 'block');
+ }
- // Set active queue song id
- activeQueueSongID = activeId;
+ // Set active queue song id
+ activeQueueSongID = activeId;
- // Clean the playlist
- var playlistItems = $('.playlist').empty();
+ // Clean the playlist
+ var playlistItems = $('.playlist').empty();
- // Print songs on playlist
- $.each(songs, function (index, item) {
- playlistItems.append(
- $('<div class="item" />')
- .toggleClass('odd', index % 2 === 0)
- .toggleClass('active', item.queueSongID === activeId)
- .text(item.ArtistName + ' - ' + item.SongName)
- .click(function () {
- userAction("playSongInQueue", [item.queueSongID])
- })
- );
- });
+ // Print songs on playlist
+ $.each(songs, function (index, item) {
+ playlistItems.append(
+ $('<div class="item" />')
+ .toggleClass('odd', index % 2 === 0)
+ .toggleClass('active', item.queueSongID === activeId)
+ .text(item.ArtistName + ' - ' + item.SongName)
+ .click(function () {
+ userAction("playSongInQueue", [item.queueSongID])
+ })
+ );
+ });
- // Scroll playlist to this music
- var playlistObject = $('.playlist');
- var activeItem = $('.playlist .item.active');
- var scrollToY = activeItem.prop('offsetTop') + ( activeItem.height() / 2 )
- - ( playlistObject.height() / 2 ) - playlistObject.prop('offsetTop');
+ // Scroll playlist to this music
+ var playlistObject = $('.playlist');
+ var activeItem = $('.playlist .item.active');
+ var scrollToY = activeItem.prop('offsetTop') + ( activeItem.height() / 2 )
+ - ( playlistObject.height() / 2 ) - playlistObject.prop('offsetTop');
- // Scroll Top Y need be 0 or upper
- if (scrollToY < 0) {
- scrollToY = 0;
- }
+ // Scroll Top Y need be 0 or upper
+ if (scrollToY < 0) {
+ scrollToY = 0;
+ }
- // If the popup is open now, will do a small animation
- if (!lastYPosition) {
- lastYPosition = scrollToY + ( scrollToY === 0 ? 200 : -200 );
- playlistObject.prop('scrollTop', lastYPosition);
- }
+ // If the popup is open now, will do a small animation
+ if (!lastYPosition) {
+ lastYPosition = scrollToY + ( scrollToY === 0 ? 200 : -200 );
+ playlistObject.prop('scrollTop', lastYPosition);
+ }
- // Animate and align the active song on center of playlist if possible
- playlistObject.animate({
- scrollTop: scrollToY
- }, 1000);
- }
- else
- // If playlist is empty, block the UI
- if (activeIndex === false){
- goToGroovesharkTab();
- }
- });
- });
+ // Animate and align the active song on center of playlist if possible
+ playlistObject.animate({
+ scrollTop: scrollToY
+ }, 1000);
+ }
+ });
+ });
- // Close window if tab is closed
- onTabCloseAccept();
+ onTabCloseAccept();
- // Show/hide notification pin
- $('#pin').toggle(!isNotificationOpen());
+ $('#pin').toggle(!isNotificationOpen());
- // On click in pin, hide it
- $('#pin').click(function(){
- window.close();
- });
- }
+ $('#pin').click(function () {
+ window.close();
+ });
+ }
}
View
7 manifest.json
@@ -1,6 +1,6 @@
{
"name": "Grooveshark Control",
- "version": "1.7.8",
+ "version": "1.7.9",
"description": "__MSG_extDescription__",
@@ -18,12 +18,13 @@
"permissions": [
"tabs",
"notifications",
- "http://grooveshark.com/*"
+ "http://grooveshark.com/*",
+ "http://preview.grooveshark.com/*"
],
"content_scripts": [{
"js": ["javascript/libs/jquery-1.6.min.js", "javascript/contentscript.js"],
- "matches": ["http://grooveshark.com/*"]
+ "matches": ["http://grooveshark.com/*", "http://preview.grooveshark.com/*"]
}],
"browser_action": {
View
2 views/popup.html
@@ -10,7 +10,7 @@
</head>
<body onload="Popup.init();">
<div id="player" class="player">
- <button id="pin" class="unpin" onclick="showNotification(true);" i18n-title="playerPin"></button>
+ <button id="pin" class="unpin" onclick="showNotification(stay=true);" i18n-title="playerPin"></button>
<button id="shuffle" class="false" onclick="userAction('toggleShuffle');" i18n-title="songShuffle"></button>
<button id="loop" class="none" onclick="userAction('toggleLoop');" title="Loop songs" i18n-title="songLoop"></button>
<button id="crossfade" class="false" onclick="userAction('toggleCrossfade');" i18n-title="songCrossfade"></button>

0 comments on commit e460ba9

Please sign in to comment.
Something went wrong with that request. Please try again.