Skip to content

Instantly share code, notes, and snippets.

@ironboy
Last active October 6, 2016 08:31
Show Gist options
  • Save ironboy/c04dc5a472ee5b3e3bbfd76dfe30e2ba to your computer and use it in GitHub Desktop.
Save ironboy/c04dc5a472ee5b3e3bbfd76dfe30e2ba to your computer and use it in GitHub Desktop.
Sort filelists in PingPong
if(!window.jQuery){
var scr = document.createElement('script');
scr.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js';
document.getElementsByTagName('head')[0].appendChild(scr);
}
var jwait = setInterval(function(){
if(!window.jQuery){return;}
clearInterval(jwait);
var $ = jQuery;
var table = $('#ppfdata').contents().find('.file-archive-table');
var sorted = [];
var first = true;
table.find('tr').each(function(i){
if(first){first = false; return;}
var me = $(this);
var date = me.find('td').last().text();
sorted.push({date:date,htmlEl:me});
});
sorted.sort(function(x,y){
return x.date < y.date ? 1 : -1;
});
var oddEven = "even";
sorted.forEach(function(item){
item.htmlEl.removeClass('odd').removeClass('even').addClass(oddEven);
oddEven = oddEven == "even" ? "odd" : "even";
table.append(item.htmlEl);
});
},100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment