Skip to content

Instantly share code, notes, and snippets.

@rfletcher
Created February 16, 2016 14:39
Show Gist options
  • Save rfletcher/5473a2b8b7307b845084 to your computer and use it in GitHub Desktop.
Save rfletcher/5473a2b8b7307b845084 to your computer and use it in GitHub Desktop.
Bookmarklet to remove duplicates from your Last.FM track list
/**
* Bookmarklet to remove duplicate entries from your Last.FM track list.
*
* Bookmarklet version:
* javascript:(%20function()%20{var%20row_to_title%20=%20function(%20$tr%20)%20{return%20$tr.find(%20%22.chartlist-name%20a:not(:empty)[title*=%E2%80%94]%22%20).attr(%20%22title%22%20).replace(%20/\s+/g,%20%27%20%27%20);};jQuery(%20%22table.chartlist%20>%20tbody%20>%20tr%22%20).each(%20function()%20{var%20$tr%20=%20jQuery(%20this%20),$siblings%20=%20jQuery(%20$tr.nextAll(%20%22tr%22%20).slice(%200,%206%20)%20),current_title%20=%20row_to_title(%20$tr%20);$siblings.each(%20function()%20{var%20$sibling%20=%20jQuery(%20this%20),sibling_title%20=%20row_to_title(%20$sibling%20);if(%20sibling_title%20!==%20%22%22%20&&%20current_title%20===%20sibling_title%20)%20{console.log(%20%22Removed%20%22%20+%20sibling_title%20);$sibling.find(%20%22.chartlist-delete%20form%20[type=submit]%22%20).click();return%20false;}});}%20);}()%20);
*
* Full version:
*/
( function() {
var row_to_title = function( $tr ) {
return $tr.find( ".chartlist-name a:not(:empty)[title*=—]" ).attr( "title" ).replace( /\s+/g, ' ' );
};
jQuery( "table.chartlist > tbody > tr" ).each( function() {
var $tr = jQuery( this ),
$siblings = jQuery( $tr.nextAll( "tr" ).slice( 0, 6 ) ),
current_title = row_to_title( $tr );
$siblings.each( function() {
var $sibling = jQuery( this ),
sibling_title = row_to_title( $sibling );
if( sibling_title !== "" && current_title === sibling_title ) {
console.log( "Removed " + sibling_title );
$sibling.find( ".chartlist-delete form [type=submit]" ).click();
return false;
}
});
} );
}() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment