There are 1 previous version of this script.
// ==UserScript==
// @name Play It Baby (last.fm)
// @namespace the.mobix@gmail.com
// @description Sort last.fm search results, by playablety
// @include http://www.last.fm/search*
// ==/UserScript==
var playItBaby =
{
sort: function(){
//First are there any result for this search?
try{
var trackResults = document.getElementById('trackResults');
}catch(e){}
if (trackResults != null){
// Okay, try to fetch table rows then
try{
var tableRows = trackResults.getElementsByTagName('tr');
}catch(e){}
var lastID = 0;
for(var i=0; i<tableRows.length; i++){
// Is this song playable?
try{
var findPlayButton = tableRows[i].getElementsByTagName('td')[0].getElementsByTagName('a')[0];
}catch(e){}
// If so move this up in list (if it not already)
if (typeof findPlayButton != "undefined"){
if (i != lastID){
var tmp = tableRows[i];
tableRows[i].parentNode.removeChild(tableRows[i]);
tableRows[lastID].parentNode.insertBefore(tmp, tableRows[lastID]);
}
lastID++;
}
}
// And lastly, fix CSS of table (odd and not odd)
if (lastID){
for(var i=0; i<tableRows.length; i++){
tableRows[i].className = this.isFloat((i + 1) / 2) ? 'odd track' : 'track';
}
}
// Done, everybody is happy now!
}else{
this.log('No results!');
}
},
isFloat: function(v){
return !isNaN(v) && isNaN(v+".1");
},
log: function(msg){
//GM_log(msg);
}
};
window.addEventListener("load", function() { playItBaby.sort(); }, false);
