Konami code for your website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
konami.js/konami.js

39 lines
724 B

/*! konami.js
https://github.com/MightyPork/konami.js
(c) MightyPork 2015, MIT License
Usage: konami(callback);
*/
(function (window) {
"use strict";
var d = window.document;
var keys = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
var progress = 0;
window.konami = function (h) {
var listener = function (e) {
if (e.keyCode == keys[progress]) {
if (++progress == keys.length) {
console.log('コナミ');
if (typeof h == 'function') {
h();
}
progress = 0;
}
} else {
if (!(e.keyCode == 38 && progress <= 2)) {
progress = 0;
}
}
};
if (d.addEventListener) {
d.addEventListener('keyup', listener);
} else {
d.onkeyup = listener;
}
};
})(window);