Skip to content

Instantly share code, notes, and snippets.

@kenmickles
Created October 27, 2011 00:37
Show Gist options
  • Save kenmickles/1318448 to your computer and use it in GitHub Desktop.
Save kenmickles/1318448 to your computer and use it in GitHub Desktop.
"Add Playlist to Playlist" bookmarklet for Rdio
/**
* This is a _very_ slightly modified version of Chris Pederick's "Add Album To Playlist" bookmarklet:
* <http://blog.chrispederick.com/post/6556221838/rdio-add-album-to-playlist-bookmarklet>
*
*/
(function () {
var interval_id = null;
var number = 0;
var playlist = 'current';
var track_count = 0;
var tracks = null;
if (window.jQuery) {
tracks = $('.track:not(.no_stream)');
track_count = tracks.length;
}
function addTrack() {
if (track_count == 0) {
alert('Sorry, no album tracks were found.');
} else if (number == track_count) {
var album = $('.header_text');
if (album.length) {
album = album.text();
} else {
album = $('.name:eq(0)').text();
}
alert('Added ' + track_count + ' tracks from the ' + $.trim(album) + ' album to the' + playlist + ' playlist.');
} else {
var menu = $('.menu_sus', tracks.eq(number));
menu.trigger('click');
$('.sus_item:eq(3) a', menu).trigger('click');
interval_id = window.setInterval(function () {
if (number == 0) {
if ($('.ui-dialog .default_button').length == 0 && $('#loading_indicator:visible').length == 0) {
window.clearInterval(interval_id);
nextTrack();
}
} else {
if ($('.ui-dialog .default_button').length == 1 && $('#loading_indicator:visible').length == 0) {
window.clearInterval(interval_id);
if (number == 1) {
playlist = ' ' + $.trim($('#playlistSelection option').eq($('#playlistSelection').get(0).selectedIndex).text());
}
$('.ui-dialog .default_button').trigger('click');
nextTrack();
}
}
}, 100);
}
}
function nextTrack() {
number++;
interval_id = window.setInterval(function () {
if ($('.ui-dialog .default_button').length == 0 && $('#loading_indicator:visible').length == 0) {
window.clearInterval(interval_id);
addTrack();
}
}, 100);
}
addTrack();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment