Live data from Hacker News

The Single Piece of JavaScript on HN

blog.watchandcode.com

21–30 of 195 posts

Re: The Single Piece of JavaScript on HN

#23
post #10

So without JS enabled you can't vote?

Without JS, return false from the vote function wouldn't happen, so I guess clicking upvote would follow node.href, which would send the vote to the server. It would work anyway, there would just be a redirect that would trigger a page refresh. Pretty cool. Just tried it out and confirmed.

Re: The Single Piece of JavaScript on HN

#24
Seeing the "auth" query. There is a chance that HN was "too clever" about it, and it might be possible to use other users id to upvote, or upvote many times, if you can figure out the hash algorithm.

Re: The Single Piece of JavaScript on HN

#25

function hide(id) { var el = document.getElementById(id); if (el) { el.style.visibility = 'hidden'; } } function vote(node) { var v = node.id.split(/_/); var item = v[1]; hide('up_' + item); hide('down_' + item); var ping = new Image(); ping.src = node.href; return false; }

What's most fascinating to me about this isn't the simplicity, it's that this code has lived for so long with almost no changes. It's a great counter-example to all the recent articles about JavaScript fatigue. It's good for us to see real examples of sites that aren't caught up in the framework of the week hype. At the end of the day we're trying to make stuff that works. ES5 vs ES6, React vs Angular vs. Ember vs. A…

For the majority of cases that I've seen, these arguments are simply excuses to avoid doing real work. It's way more fun to decide whether your amazingly awesome Unicorn startup is going to use React or Angular, or Express vs. Rails, or whatever than it is to actually go through the hard work of building a customer base and making money.

Re: The Single Piece of JavaScript on HN

#29

If we ever make it around to a second piece of javascript on here, can I request that it be a collapse comment function? I promise i won't ask for anything else.

Is there anything like Reddit Enhancement Suite for HN? Any recommendations out there?

Yes, aptly named "Hacker News Enhancement Suite". I use it and think it does fine, mainly just for collapsing comments.

https://chrome.google.com/webstore/detail/hacker-news-enhanc...

Re: The Single Piece of JavaScript on HN

#30
post #8

Not much to say, really. Just some simple code. What I'm curious is if someone can reiimplement this without and javascript.

Well there appear to be two things stopping this: - Hiding two elements on the page (one can be hidden with the CSS :visited selector) - Remaining with your position on the page whilst also sending a message to the server and without opening new windows. So the only way to do the task is to send a full request to the server which would return you to the page with the buttons correctly disabled. Extra load on the serv…

You could render the vote buttons in iframes, so just the iframe would reload. But you'd have to load N iframes for N vote buttons on page load. Not worth the performance hit.
Post reply on HN