Skip to content

Instantly share code, notes, and snippets.

@jRimbault jRimbault/konami.js
Last active Aug 17, 2018

Embed
What would you like to do?
/**
* Trigger callback when the user inputs the konami code
* @param {Function} callback
* @returns {Function} event handler
*/
function konami(callback) {
'use strict'
let kkeys = []
// up,up,down,down,left,right,left,right,B,A
const konami = '38,38,40,40,37,39,37,39,66,65'
return event => {
kkeys.push(event.keyCode)
if (kkeys.toString().indexOf(konami) >= 0) {
callback(event)
kkeys = []
}
}
}
const handler = konami(console.log)
window.addEventListener('keydown', handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.