Skip to content

Instantly share code, notes, and snippets.

@kenglxn
Last active August 19, 2017 15:31
Show Gist options
  • Save kenglxn/9527c8ac066e0f48e17c to your computer and use it in GitHub Desktop.
Save kenglxn/9527c8ac066e0f48e17c to your computer and use it in GitHub Desktop.
simple js function to set up konami kode easter egg (up, up, down, down, left, right, left, right, b, a, enter)
(function () {
var buffer,
latchId,
onKonami,
konamiChk,
code = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
onKonami = function () {
console.log("konami!!!");
};
konami = function (ev) {
buffer = buffer || code.slice();
if (buffer[0] === ev.keyCode) {
window.clearTimeout(latchId);
buffer.splice(0, 1);
if (buffer.length === 0) {
onKonami();
}
latchId = window.setTimeout(function () {
buffer = code.slice();
}, 500);
}
};
window.addEventListener("keyup", konami);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment