Skip to content

Instantly share code, notes, and snippets.

@iwek
Last active December 14, 2015 13:19
Show Gist options
  • Save iwek/5092491 to your computer and use it in GitHub Desktop.
Save iwek/5092491 to your computer and use it in GitHub Desktop.
Organize or Sort Pinterest Images by Repins
//cleanup and sort elemets that have repins
//grab all pins
var mylist = $('.Pin');
//find all pins that have repins
var listitems = mylist.find('.socialItem');
var list = listitems.filter(function(f,i){
var test = Number( $(i).text().trim().replace("repins", "").replace("repin", "") );
if(test>0){
return i;
}
});
//trim the contents of the repins element to just a number and compare them against each other to sort
list.sort(function(a, b) {
var compA = Number( $(a).text().trim().replace("repins", "").replace("repin", "") );
var compB = Number( $(b).text().trim().replace("repins", "").replace("repin", "") );
return (compA == compB) ? 0 : (compA > compB) ? -1 : 1;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment