Last active
December 28, 2020 03:30
-
-
Save unitycoder/296222fc4e4c6d7c8cea to your computer and use it in GitHub Desktop.
LudumDare34 - Vote with ArrowKeys (left = yes, right = no)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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()} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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