Skip to content

Instantly share code, notes, and snippets.

@aJanuary
Last active January 8, 2021 08:53
Show Gist options
  • Save aJanuary/67d1113d845c467445fb6f0cc100ebcc to your computer and use it in GitHub Desktop.
Save aJanuary/67d1113d845c467445fb6f0cc100ebcc to your computer and use it in GitHub Desktop.
A Greasemonkey compatible user script for indicating whether a reply in a hacker news thread is from somehow new, or someone who appeared earlier in the thread.
// ==UserScript==
// @name HN comment ancestory
// @version 1
// @include https://news.ycombinator.com/item?*
// @grant none
// ==/UserScript==
const $commentTree = document.getElementsByClassName('comment-tree')[0];
const $commentRows = $commentTree.children[0].children
const usernameStack = [];
let prevIndent = 0;
for (let i = 0, len = $commentRows.length; i < len; i++) {
const $row = $commentRows[i];
const $rowTable = $row.children[0].children[0];
const indent = $rowTable.getElementsByClassName('ind')[0].children[0].width / 40;
const $username = $rowTable.getElementsByClassName('hnuser')[0];
const username = $username.innerText;
let indicatorText;
if (indent <= prevIndent) {
usernameStack.splice(indent);
}
const index = usernameStack.indexOf(username);
if (index === -1) {
indicatorText = '*';
} else {
indicatorText = '↑'.repeat(indent - index);
}
usernameStack.push(username);
prevIndent = indent;
$username.innerText = indicatorText + " " + username;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment