Skip to content

Instantly share code, notes, and snippets.

@bakkot
Created December 18, 2014 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bakkot/1ab53b25907bfc82d780 to your computer and use it in GitHub Desktop.
Save bakkot/1ab53b25907bfc82d780 to your computer and use it in GitHub Desktop.
SSC sort by number of children (only top-level threads)
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'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment