Reddit-like Collapsible Threads for Hacker News

Tuesday, February 16th, 2010 at 10:24 +0000 (UTC) by Alexander Kirk

I enjoy consuming and participating at Hacker News by Y Combinator resp. Paul Graham.

One thing that needs improvement is the reading comments there. At times it happens that the first comment develops into a huge thread, and then the second top-level comment (which might also be well worth reading) disappears somewhere down into the page.

Collapsible Threads at Hacker News through a bookmarkletReddit has combatted this common problem by making threads easily collapsible. I think it is worth having this also on Hacker News, so I implemented it and wrapped it into a bookmarklet so that you can use this functionality on-demand at Hacker News.

Drag this to your bookmarks bar: collapsible threads

As soon as it is available in your bookmarks bar, go to Hacker News and click on it when viewing a comments page. Next to each thread a symbol [+] will appear. Click it to collapse the thread and it will change to a [-]. Click that to expand the thread again.

I have licensed the source code under an MIT License. Click here to view the source code of hackernews-collapsible-threads.js. (Actually for caching reasons the bookmarklet currently loads hackernews-collapsible-threads-v6.js which is actually just the same)

The Hacker News HTML source code seems quite fragile in the sense that the comments section of a page can't be identified in a really unique way (for example it does not have an HTML id attribute), so it might break when the layout of the page changes. This is why the bookmarklet is actually only a loader for the script on my server. I have tuned the HTTP headers in a way that your browser should properly cache the script so that the speed of my server should not affect the loading of the bookmarklet.

Enjoy :)

If you use Hackernews on another URL than news.ycombinator.com or hackerne.ws, use this bookmarklet: collapsible threads (no domain check)

Update March 18, 2011: Paul Biggar has contributed a greasemonkey script that also works on Firefox 4. I have adapted it so that it also works (which basically involved copying the jQuery script above mine) in Safari and Chrome (using NinjaKit).

Install Greasemonkey script

Install Paul Biggar's Greasemonkey script

Update November 22, 2011: Eemeli Aro has sent me a little CSS tweak so that the lines don't move around when collapsing. The code downloadable from above contains his code. Thank you!

6 Responses to “Reddit-like Collapsible Threads for Hacker News”

  1. uberVU - social comments Says:

    Social comments and analytics for this post...

    This post was mentioned on Twitter by akirk: New blog post: Reddit-like Collapsible Threads for Hacker News http://alexander.kirk.at/2010/02/16/collapsible-threads-for-hacker-news/...

  2. Reddit-like Collapsible Threads for Hacker News » alexander kirk … · Staringfrog.com Says:

    [...] Read more from the original source: Reddit-like Collapsible Threads for Hacker News » alexander kirk … [...]

  3. alexandroid Says:

    How about making it a Greasemonkey script so one do not have to click on a bookmarklet?

  4. Reed Says:

    Is this still working? It's broken for me. (Chrome 4.0.249.89, Win7)

  5. Alexander Kirk Says:

    Yes it's working, just also tried it under Chrome (Mac, but should be the same).

  6. Reed Says:

    Works for me too now. The other day it was failing on this thread:

    http://news.ycombinator.com/item?id=1139185