There is 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:
CopyCode 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: copy Code 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 ");
}