Saturday, June 21, 2014

Flat Hacker News

Threaded conversations in Hacker News (HN) can be a pain at times. It's easy to lose context as you scroll down a long discussion. Jeff Atwood has written about numerous issues with threaded discussions and suggests limiting the level of replies allowed. So, how do we go about doing that without asking the HN maintainers ?

Update: This latest version of the Flat HN bookmarklet is available here.

TL;DR Edition - Drag this link, Flat/Threaded HN, to your bookmarks. Open a discussion on HN and click on the newly created "Flat/Threaded HN" bookmark.

Deeply threaded dicussion

HN's html suggests hiding deeply threaded comments should be simple. A spacer GIF appears to be used to indent comments, and those spacers used for indentation seem to have width in multiples of 40 in proportion to the depth of the comment.

I wrote some quick-and-dirty javascript to hide comments at depth > 1. This shows only the top level comments, and replies to those comments have reduced font size (Edit: Based on feedback, the font size is no longer reduced. The second line in the JS file allows you to reduce font size if you prefer it that way). Replies deeper than that are hidden.

While this works fine, it's a tad inconvenient to have to copy/paste this JS code into the browser's web console every time a HN discussion page is opened. My first thought was to simulate a browser in JS. Instead of coming to HN, people who want a "flat" HN go to a different web page which has some JS to pull in HN content and modify all the links, forms etc. so that the "flat" view is maintained throughout. This seemed excessively complex, so I looked for simpler ways to inject javascript into a web page.

Bookmarklets turned out to be a good solution for this. The idea is to have some javascript as a bookmark, and this script gets executed in the context of the page that is open when you click on the bookmarklet. Drag this link, Flat/Threaded HN, to your bookmarks. Open a discussion on HN and click on the newly created "Flat/Threaded HN" bookmark. That should give you a flat HN. Clicking on the bookmark again will revert the page back to the threaded view.

 Hope this improves your HN experience !

No comments:

Post a Comment