Hn.js
news.ycombinator.com
news.ycombinator.com
function vote (id, how, auth, _goto) {
vis($('up_' + id), how == 'un');
vis($('down_' + id), how == 'un');
var unv = '';
if (how != 'un') {
unv = " | <a id='un_" + id + "' class='clicky' " +
"href='" + vurl(id, 'un', auth, _goto) + "'>" +
(how == 'up' ? 'unvote' : 'undown') + "</a>"
}
$('unv_' + id).innerHTML = unv;
new Image().src = vurl(id, how, auth, _goto);
}
Hide the up_ and down_ vote buttons, then either erase the innerHTML of the un_ vote div or construct new HTML for it from scratch. To top it all off, let's just inform the server of the vote by creating a new throwaway Image element, because it works everywhere and is less verbose than fetch.I don't think it's less verbose; fetch(vurl(...)) would work perfectly fine, and I think it's clearer what the intent is. fetch is also very widely supported by now. I don't blame anyone for writing it the way it was, back when fetch probably wasn't available, but I'd definitely just use that today.
If not you could craft a page which upvote posts for the current visitor (if they're logged in HN)
You could mitigate it with server side checks (or maybe some new browser tech I don't know about?) but I think the synchroniser token pattern is still the current solution.
Yes, it looks like it does. Also, the vote auth param is different for every link.
In any case, an SPA is not the solution for this problem.
I might not agree completely, but I see the wisdom in it.
Here is an example. Let's put this into a file called file.lisp:
(defmacro foo ())
(defwidget widg ()) ;; I just made up defwidget: it doesn't exist!
(mac bar ())
Now, let's run Exuberant Tags (ctags): $ ctags file.lisp
$ cat tags
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.9~svn20110310 //
foo file.lisp /^(defmacro foo ())$/;" f
widg file.lisp /^(defwidget widg ())$/;" f
Hey look, ctags recognized my defwidget invention and index widg as a tag.Where is Graham's mac?
Always call your custom definers defsomething, and put them in the first column as (defsomething name* ...*. Then ctags will index you custom defined constructs.
Also, saving a couple of character in defining a macro is false economy, because a macro should be used at least several times and considerably condense your program and make it more readable.
defmacro is already abbreviated; it could be define-macro which would be bad. defmac is a nice possibility.
For most of us less insane folks, we like to be able to read our code.
Interestingly, Paul Graham seems to not have taken this approach towards writing. I mean, if u can omit bnch o chars in wrds & stll gt the meanin acrx, why bthr wrtin ful wrds or sntnces?
fetch(url + next).then(r => r.json()).then(newstory);
It's not supported before Edge 12 [1], it probably causes a parse error on Edge 11 and IE 11, neutralizing the whole Javascript file.[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
For my personal single-html projects, I prefer a straightforward coding style that avoids external dependencies. I implement what I need in a simple, quick, and efficient manner using only native browser APIs, supplemented with a few helpers like those in 'Hn.js' to make the rest of the code shorter.
function $ (id) { return document.getElementById(id); }
I love this, it’s the ultimate lightweight jquery alternative. function $ (s) { return document.querySelectorAll(s); }
Would be more jquery like.if ( ! Nodelist.prototype.map ) { Nodelist.prototype.map = Array.prototype.map }
So map() works. forEach() already does.
dang's comment: https://news.ycombinator.com/item?id=17922414