Last active
May 10, 2016 03:33
-
-
Save techslides/5a41782577b0e4dbeeba to your computer and use it in GitHub Desktop.
Auto Sort Pinterest Pins by Likes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Go to any page with pins (a board, your pins, search results, etc) and open JavaScript Console (Ctrl+Shift+J on windows OR option+command+J on mac) and paste in this code: | |
//sort by likes, adjust amount of pins/pages you want to collect first | |
var pages = 5; | |
var count = 0; | |
var mylist = []; | |
var timeout; | |
load(); | |
function load(){ | |
$('.Pin').each(function(){ | |
mylist.push( $(this)[0] ) | |
}); | |
$(window).scrollTop( $(document).height() ); | |
timeout = window.setTimeout(load, 4000); | |
count++; | |
if(count==pages){ | |
finish(); | |
} | |
} | |
function finish(){ | |
window.clearTimeout(timeout) | |
console.log(mylist.length); | |
var list = mylist.filter(function(f){ | |
if( $(f).find('.likeCountSmall').length>0 ){ | |
return f; | |
} | |
}); | |
console.log(list); | |
list.sort(function(a, b) { | |
var compA = Number( $(a).find('.likeCountSmall').text().trim() ); | |
var compB = Number( $(b).find('.likeCountSmall').text().trim() ); | |
return (compA == compB) ? 0 : (compA > compB) ? -1 : 1; | |
}); | |
$(".Grid").before('<div id="organized"/>').remove(); | |
$.each(list, function(idx, itm) { | |
$("#organized").append($(itm)); | |
}); | |
$('.Pin').css({'clear': 'both', 'position': 'static'}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment