Skip to content

Instantly share code, notes, and snippets.

@kappa7194
Created October 18, 2012 13:33
Show Gist options
  • Save kappa7194/3911825 to your computer and use it in GitHub Desktop.
Save kappa7194/3911825 to your computer and use it in GitHub Desktop.
JavaScript Konami code
<!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