Last active
February 17, 2016 17:04
-
-
Save rummik/10633824 to your computer and use it in GitHub Desktop.
Konami Kode in JS.
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
/** | |
* 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