Skip to content

Instantly share code, notes, and snippets.

@jefvlamings
jefvlamings / hn-comment-collapse.js
Created March 3, 2017 10:32
Collapse all Hackernews comments
var toggs = document.getElementsByClassName('togg');
for(var i=0; i<toggs.length; i++) {
toggs[i].click();
}
@jefvlamings
jefvlamings / hn-comment-sort.js
Last active October 16, 2023 19:14
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)