Skip to content

Instantly share code, notes, and snippets.

@bakkot
Created December 18, 2014 06:01
Show Gist options
  • Save bakkot/4b0b9f62b3ee4230f4d5 to your computer and use it in GitHub Desktop.
Save bakkot/4b0b9f62b3ee4230f4d5 to your computer and use it in GitHub Desktop.
SSC sort by number of children (including in subthreads)
javascript:function c(l){return l.querySelectorAll('li.comment').length;}function s(e){var h=[];for(var i=0; i<e.children.length; ++i){h.push({'E':e.children[i],'C':c(e.children[i])});}var t=h.sort(function(a,b){return a.C-b.C;});for(var i=t.length-1;i>0;--i){e.insertBefore(t[i].E,t[0].E);}}s(document.querySelector('ol.commentlist'));var d=document.querySelectorAll('ul.children');for(var i=0;i<d.length;++i){s(d[i]);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment