JavaScriptKonamiCode has an egg on Facebook:
Log on to facebook.com and click anywhere on your homepage. Enter Up, Up, Down, Down, Left, Right, Left, Right, B, A, and Enter on the keyboard, click the page or scroll through the scroll bar, and you will find special changes (such ).
A friend who has been playing "soul" will surely be able to see at a glance that the entered character is the "secret" in "soul ". In fact, the term "secret" is Konami Code. For details, see the figure below:
So how can I add a similar egg on my own page with JavaScript?
Abhi provides a general idea in the article Konami Code on Facebook: How to implement it on your site:
The Code is as follows:
Var $ = {
Enabled: false,
Tmp: Array (),
_ KonamiCode: Array (65,66, 39,37, 39,37, 40,40, 38,38 ),
Init: function (){
This. tmp = Array (65,66, 39,37, 39,37, 40,40, 38,38 );
},
KonamiCode: function (e ){
If (! This. enabled ){
Var t = this. tmp. pop ();
If (e. keyCode-t) = 0 ){
If (this. tmp. length = 0 ){
This. enabled = true;
}
} Else {
This. init ();
}
} Else {
This. action ();
}
},
// Change the action () function to whatever you want
Action: function (){
// Alert ("Konami Code Activated ");
}
}
However, the Abhi method is redundant. Jan Jarfalk provides a short and concise code in the message:
The Code is as follows:
Var k = [];
Function (e ){
K. push (e. keyCode );
If (k. toString (). indexOf ("38,38, 40,40, 37,39, 37,39, 66,65")> = 0 ){
// Alert ("Konami Code Activated ");
}