Skip to content

Instantly share code, notes, and snippets.

@mininmobile
Last active September 27, 2018 22:04
Show Gist options
  • Save mininmobile/2d814a5c8e4ef2a8f0a8d7a241d8102e to your computer and use it in GitHub Desktop.
Save mininmobile/2d814a5c8e4ef2a8f0a8d7a241d8102e to your computer and use it in GitHub Desktop.
Easter egg "konami code" JS library.

konami.js

A simple, lightweight, easter egg library for detecting the Konami Code.

Installation

Add this to your <head>:

<!-- regular -->
<script src="https://gistcdn.githack.com/mininmobile/2d814a5c8e4ef2a8f0a8d7a241d8102e/raw/5788c4732deb0844750066a43dbbd8c1ad6ed1ba/konami.js"></script>

<!-- minified -->
<script src="https://gistcdn.githack.com/mininmobile/2d814a5c8e4ef2a8f0a8d7a241d8102e/raw/5788c4732deb0844750066a43dbbd8c1ad6ed1ba/konami.min.js"></script>

Usage

onKonami(() => alert("ayy lmao"));
/**
* konami.js by \@zvava\@toot.cafe
*
* @param {function} callback
*/
function onKonami(callback) {
let input = "";
let key = "38384040373937396665";
document.addEventListener("keydown", (e) => {
input += "" + e.keyCode;
if (input == key) return callback();
if (!key.indexOf(input)) return;
input = "" + e.keyCode;
});
}
/** konami.js by \@zvava\@toot.cafe
* @param {function} callback*/
function onKonami(c){let i="";let k="38384040373937396665";document.addEventListener("keydown",(e)=>{i+=""+e.keyCode;if(i==k)return c();if(!k.indexOf(i))return;i=""+e.keyCode;});}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment