Skip to content

Instantly share code, notes, and snippets.

@bakkot
bakkot / SSC-SBC1
Created December 18, 2014 06:01
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]);}