Skip to content

Instantly share code, notes, and snippets.

@joshfreemanIO
Created March 2, 2013 01:49
Show Gist options
  • Save joshfreemanIO/5069260 to your computer and use it in GitHub Desktop.
Save joshfreemanIO/5069260 to your computer and use it in GitHub Desktop.
Plays the Metal Gear Solid "Alert" sound when the Konami Code is entered. Modify path to local instance of the sound file.
counter = 0;
window.onkeydown = function(e){konamicode(e.which)}
function konamicode(button)
{
var code = new Array(38,38,40,40,37,39,37,39,66,65);
if(code[counter] === button)
{
counter++;
if(counter === 10){Alert();counter = 0; return false;}
return false;
}
else if (button === 38)
{
counter = 1;
return false;
}
else
{
counter = 0;
return false;
}
}
function loadWAVE()
{
audio = document.createElement("audio");
audio.setAttribute('autoplay','autoplay');
audio.setAttribute('id','MGSAlert');
source = document.createElement("source");
source.setAttribute('src','Alert.wav');
audio.appendChild(source);
audio.setAttribute('src','Alert.wav');
document.body.appendChild(audio);
}
function Alert()
{
var audio = document.getElementById("MGSAlert");
if (document.getElementById("MGSAlert") == null)
{
loadWAVE();
}
else
{
audio.play();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment