Advertisement
mspotilas

Random order to Blogger popular posts

Dec 3rd, 2011
1,606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type='text/javascript'>
  2. //<![CDATA[
  3. // Random order to Popular Posts using jQuery / MS-potilas 2011
  4. // Put this code in a html/javascript gadget or before </body>.
  5. // See http://yabtb.blogspot.com/2011/12/shuffle-blogger-popular-posts.html
  6. var ul = $('.popular-posts ul');
  7. var lis = $('.popular-posts ul li');
  8. if(lis.length>1) {
  9.   for(var i=lis.length-1;i;i--) {       // fisher-yates/knuth
  10.     var j=parseInt(Math.random()*i);
  11.     lis[j] = lis.splice(i,1,lis[j])[0]; // swap lis[i]&lis[j]
  12.   }
  13.   lis.appendTo(ul);
  14. }
  15. //]]>
  16. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement