Hacker News Like Button

Let me begin by thanking you all for your love; my last post made it to the Hacker News front page and also got some buzz in Twitter, Reddit and Facebook. I am not just thanking the ones that agreed with me and upvoted my post, those of you who have disagreed and commented are valued equally.

I have named my blog ‘Hacks and Thoughts’ but my last two posts (only ones so far) were both thoughts so I was due for a hack. So here it comes.

The Idea

A couple of times, I have submitted web-contents to Hacker News only to find that it has already been submitted there. When my article made it to the HN front-page, I realized that there is another disconnect as well: readers who come to the page from other sources (subscription, twitter etc.) are not aware of the attention and thus remain isolated from the interesting discussions. In my last post, I invited them to join the discussion by providing a link at the end but that was not a very good solution.

The Research

Having been around HN for some time, I suspected that someone might have already come-up with a solution. I searched for Hacker News submission tools but only found a bookmarklet and a Chrome extension. A like button is much more provoking for readers visiting a page than a bookmarklet or the extension which has to be pre-installed. Also, it would not help readers realize the discussions that might be going on. I decided to explore it a little bit.

The Details

Hacker News needs you to be logged in to your account for upvoting and does not provide a programmatic way to do that on your behalf. I remembered from earlier experiences that a resubmission (once per user) counted as an upvote. I found that the bookmarklet used the following javascript to submit the news:


Basically, we could pass the url (as query string u) and the title (as query string t) to http://news.ycombinator.com/submitlink programmatically and the user would only need to click submit given that s/he is already logged in. That was one part of the like button.

The other part was getting the HN points for the submission so that it could be displayed in the like button. This would indicate the HN hotness right on the page without the need for the user to go find in HN. I was trying to come-up with a way to scrape the points from the thread but found that HN actually offers a search API that returns json response. On top of that, it offered scoring different attributes for matching so it was possible to only search submitted urls that matched the url of the current content and retrieve the score if the submission already existed.

That’s it! The rest is skinning the cat and the recently released Twitter Bootstrap toolkit came handy in putting a page together.

The Test

Pre-launch, every thing seems to be working fine (on three browsers that is ) except for the not-so-nice user expereince of having to close the submit pop-up window after submitting. If this takes off after launch, the large scale of requests might affect HN search API. I didn’t see any rate-limiting details for the API but there might be a limit. I registered a domain and forwarded it to my hobby project server so that may go down as well. If the community thinks this is useful, I am willing to build and maintain it as a reliable service.


7 thoughts on “Hacker News Like Button

  1. > If this takes off after launch, the large scale of requests might affect HN search API. No! no! no! To be a good citizen, you must cache the HN API call. Don’t hit it on every user request for the page. Upvoting will just blend into the normal HN load.


  2. Jan de Vos

    To be honest, I’d prefer a link to HN where I can then upvote. The link could land on a submission page if the article had not been submitted before.


  3. Dany

    So yCombinator should do something to avoid it, it can be used to do fake votes wo informing users…..


  4. Jeff

    To Dany:No it can’t, this isn’t a scraper, so when you enter your Username/Password it’s going directly to HN, not to him — he’s reframing HN pages in an iframe window


  5. Hey, I recently started using your button on my site and it’s very nice, good work!However, I have a small problem: If a post hasn’t been submitted to HN yet, the button doesn’t send me to a submit page, I just get "No such item." Is this expected behavior?


Comments are closed.