Skip to content

Instantly share code, notes, and snippets.

@iwek
Last active December 14, 2015 13:19
Show Gist options
  • Save iwek/5092629 to your computer and use it in GitHub Desktop.
Save iwek/5092629 to your computer and use it in GitHub Desktop.
Sort and Organize Pinterest Images by Likes
//cleanup for likes
$(".likes").each(function() {
var num = Number($(this).text().trim().replace("likes", "").replace("like", ""));
$(this).html(num);
});
//sort
var mylist = $('.Pin');
var listitems = mylist.find('.likes:not(:contains(0))'); //do not match on elements that have 0 likes
listitems.sort(function(a, b) {
var compA = Number( $(a).text() );
var compB = Number( $(b).text() );
return compA > compB ? -1 : 1;
});
//empty main section
$(".Grid").before('<div id="organized"/>').remove();
//append sorted items
$.each(listitems, function(idx, itm) {
$("#organized").append($(itm).parents('.Pin'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment