Created
November 3, 2014 18:42
-
-
Save techslides/dc74848ea7bd5b2a46e9 to your computer and use it in GitHub Desktop.
Auto Sort Pinterest Pins by Repins
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 repins, 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('.repinCountSmall').length>0 ){ | |
return f; | |
} | |
}); | |
console.log(list); | |
list.sort(function(a, b) { | |
var compA = Number( $(a).find('.repinCountSmall').text().trim() ); | |
var compB = Number( $(b).find('.repinCountSmall').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'}); | |
} |
Hey. Thanks for the code. But the code is not functioning well because it can't sort non number repins for example 1.2k, 1m, etc. The Number function eliminate any character after numbers, so the k and m is neglected when sorting pins. Any solution?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the code. Could you clarify the steps please? I opened the JS Console but then ...........?
Thanks,
David