Skip to content

Instantly share code, notes, and snippets.

@jefvlamings
Last active October 16, 2023 19:14
Show Gist options
  • Save jefvlamings/6c403abb71dc4af398ce936859f3ba60 to your computer and use it in GitHub Desktop.
Save jefvlamings/6c403abb71dc4af398ce936859f3ba60 to your computer and use it in GitHub Desktop.
Sort Hackernews comments by number of replies
var commentTree = document.getElementsByClassName('comment-tree')[0].getElementsByTagName('tbody')[0];
var colls = document.getElementsByClassName('comtr');
var newColls = []
for(var i=0; i<colls.length; i++) {
newColls.push(colls[i])
}
newColls.sort(function(a,b) {
var counta = parseInt(a.getElementsByClassName('togg')[0].getAttribute('n'), 10)
var countb = parseInt(b.getElementsByClassName('togg')[0].getAttribute('n'), 10)
return counta == countb ? 0 : (counta > countb ? -1 : 1)
});
commentTree.innerHTML = "";
for(var i=0; i<newColls.length; i++) {
commentTree.appendChild(newColls[i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment