JavaScript Konami Code Implementation _JAVASCRIPT Skills

Source: Internet
Author: User
There's an Easter egg on Facebook:
Login facebook.com, click anywhere on your homepage, keyboard input up, up, down, down, left, right, left, right, B, A, enter, click on the page or scroll through the scroll bar, you will find special changes (pictured below), Hey ^^

Played "The Soul Dou Luo" friend, certainly one eye can see the input character originally is "The Soul Dou Luo" in "The Secret". In fact, the term "secret" is called Konami Code, see illustration in detail:

So how do you add a similar egg to your own page with JavaScript?
Abhi provides a general idea in the article "Konami Code on Facebook:how to implement it on your site":

Copy Code code 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 your want to
Action:function () {
Alert ("Konami Code activated");
}
}

However, the Abhi method is still redundant point, the Jarfalk in the message provided a short code:
Copy Code code 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.