Skip to content

Instantly share code, notes, and snippets.

@rummik
Last active February 17, 2016 17:04
Show Gist options
  • Save rummik/10633824 to your computer and use it in GitHub Desktop.
Save rummik/10633824 to your computer and use it in GitHub Desktop.
Konami Kode in JS.
/**
* konami.js - copyright (c) 2014-2016 rummik
* license: Public Domain / CC0 / WTFPL
* source: https://gist.github.com/rummik/10633824
* usage:
* window.addEventListener('konami', function() { ... })
* window.onkonami = function() { ... }
*/
(function() {
var kode = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
var stak = new Array(kode.length);
window.addEventListener('keydown', function konami(event) {
stak.shift();
stak.push(event.keyCode);
if (stak.toString() == kode) {
window.dispatchEvent(new CustomEvent('konami'));
if (typeof window.onkonami == 'function') {
window.onkonami();
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment