Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active December 28, 2020 03:30
Show Gist options
  • Save unitycoder/296222fc4e4c6d7c8cea to your computer and use it in GitHub Desktop.
Save unitycoder/296222fc4e4c6d7c8cea to your computer and use it in GitHub Desktop.
LudumDare34 - Vote with ArrowKeys (left = yes, right = no)
// instructions: copy paste one script line below to your browser debugger console (press F12 to open it). Left = Yes, Right = No
document.onkeydown=function(e){document.getElementById(e.keyCode==37?"kill-good":e.keyCode==39?"kill-bad":"sg").click()}
// these are just for trying to make the same code shorter
// original code
document.onkeydown=function(e){e=e||window.event;document.getElementById(e.keyCode==37?"kill-good":e.keyCode==39?"kill-bad":"sg").click();};
// optimized
document.onkeydown=function(e){document.getElementById(e.keyCode==37?"kill-good":e.keyCode==39?"kill-bad":"sg").click()}
// shorter version. Left = yes, Other keys = no
document.onkeyup=function(e){document.getElementById(e.keyCode==37?'kill-good':'kill-bad').click()}
// shorteting the script
document.onkeyup=function(e){document.getElementById('kill-'+(e.keyCode==37?'good':'bad')).click()}
document.onkeyup=function(e){kill_VoteIdea(e.keyCode==37?1:0)}
document.onkeyup=function(e){kill_VoteIdea(e.keyCode==37)}
// shortest
document.onkeyup=(e)=>kill_VoteIdea(e.keyCode==37)
// shorter'er
onkeyup=(e)=>kill_VoteIdea(e.keyCode==37)
onkeyup=_=>kill_VoteIdea(_.keyCode<39)
onkeyup=_=>kill_VoteIdea(_.which<39)
// shorter'est!
onkeyup=_=>kill_VoteIdea(_.which%3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment