Last active
January 4, 2026 00:01
-
-
Save vishnuharidas/abadbbf1a74c6a32283d7b6dca1f4032 to your computer and use it in GitHub Desktop.
A tiny browser-console script for Hacker News that displays each comment's indentation level directly inside the comment cell.
This file contains hidden or 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
| function showIndentNumberInTDs({ | |
| selector = "td.ind", | |
| attr = "indent", | |
| className = "indent-label", | |
| color = "#ff660088", | |
| fontSize = "28px", | |
| fontWeight = "600", | |
| padding = "4px" | |
| } = {}) { | |
| const tds = document.querySelectorAll(selector); | |
| tds.forEach(td => { | |
| const n = parseInt(td.getAttribute(attr), 10); | |
| if (!Number.isFinite(n)) return; | |
| // Remove existing label if re-running | |
| td.querySelectorAll(`:scope > .${className}`).forEach(el => el.remove()); | |
| // Ensure positioning context | |
| if (getComputedStyle(td).position === "static") { | |
| td.style.position = "relative"; | |
| } | |
| const label = document.createElement("div"); | |
| label.className = className; | |
| label.textContent = n; | |
| Object.assign(label.style, { | |
| position: "absolute", | |
| top: padding, | |
| right: padding, | |
| color, | |
| fontSize, | |
| fontWeight, | |
| lineHeight: "1", | |
| pointerEvents: "none", | |
| userSelect: "none", | |
| zIndex: 1 | |
| }); | |
| td.appendChild(label); | |
| }); | |
| return { updated: tds.length }; | |
| } | |
| // Run it | |
| showIndentNumberInTDs(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Reason for this: I lost track of what I am reading on this thread: https://news.ycombinator.com/item?id=46473348