by lolinder · 2y ago · 0 comments
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.