Created
October 18, 2012 13:33
-
-
Save kappa7194/3911825 to your computer and use it in GitHub Desktop.
JavaScript Konami code
This file contains 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
<!doctype html> | |
<html> | |
<head> | |
<title>Code</title> | |
<script> | |
"use strict"; | |
var Konami = function (handler) { | |
var self = this; | |
self.code = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65]; | |
self.status = 0; | |
self.parse = function (key) { | |
if (key.keyCode == self.code[self.status]) { | |
self.status++; | |
if (self.status === self.code.length) { | |
self.status = 0; | |
if (typeof self.raise === "function") { | |
self.raise(); | |
} | |
} | |
} | |
} | |
self.raise = handler; | |
} | |
var konami = new Konami(function () { | |
console.info("LOL"); | |
}); | |
window.onkeydown = konami.parse; | |
</script> | |
</head> | |
<body> | |
<h1>Code</h1> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment