Skip to content

Instantly share code, notes, and snippets.

@rowanmanning
Last active October 12, 2015 15:08
Show Gist options
  • Save rowanmanning/4045521 to your computer and use it in GitHub Desktop.
Save rowanmanning/4045521 to your computer and use it in GitHub Desktop.
Simple Konami Code with jQuery
<!DOCTYPE html>
<meta charset="utf-8"/>
<title>↑ ↑ ↓ ↓ ← → ← → B A</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="konami.js"></script>
<script>
// On document ready
$(function () {
// When the Konami Code is typed
$('body').on('konami', function () {
// Replace this with something awesome
alert('KONAMI!');
});
});
</script>
(function ($) {
var sequence = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
var keys = [];
// Bind events to body on load
$(function () {
var body = $('body');
body.on('keydown', function (event) {
// Update pressed keys
keys.push(event.which);
if (keys.length > sequence.length) {
keys.shift();
}
// Do our keys match the sequence?
if (keys.toString() === sequence.toString()) {
body.trigger('konami');
}
});
});
} (jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment