Javascript konami code implementation code

Source: Internet
Author: User

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 ");
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.