Created
December 18, 2014 06:01
-
-
Save bakkot/4b0b9f62b3ee4230f4d5 to your computer and use it in GitHub Desktop.
SSC sort by number of children (including in subthreads)
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
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