MyBB Community Forums

Full Version: Implementing the Konami Code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Introduction
The Konami Code, used in many Konami Video Games, is a series of keystrokes which, when triggered, cause an Easter Egg. The keystrokes are up, up, down, down, left, right, left, right, B, A, Enter. Today, I'll be showing you how to implement this in your website using only one template edit. Best of all, it only uses JavaScript. Let's begin.

Open headerinclude. Insert at the bottom:

<script type="text/javascript">
if (window.addEventListener) {
    var keys = [],
        konami = "38,38,40,40,37,39,37,39,66,65";
    
    window.addEventListener("keydown", function(e){
        keys.push(e.keyCode);
        
        if (keys.toString().indexOf(konami) >= 0) {
            alert("lulz");
            keys = [];
        };
    }, true);
};
</script>

The key points here are:

        konami = "38,38,40,40,37,39,37,39,66,65";
            alert("lulz");

"konami" is your Konami Code. To anyone, it's a string of meaningless numbers. But to you and I educated webmasters, they're the required keystrokes.
"alert("lulz");" is what happens when the Konami Code is triggered. So here, it causes an alert box to pop up saying "lulz".

Let's say you have Pirata's NewPoints and CouponCodes installed and wanted it so that, if the User decided to use the Konami Code, it'd send them to the Coupon Code page. You'd change our alert box to:

window.location = '{$mybb->settings['bburl']}/couponcodes.php';

So your code would be:

<script type="text/javascript">
if (window.addEventListener) {
    var keys = [],
        konami = "38,38,40,40,37,39,37,39,66,65";
    
    window.addEventListener("keydown", function(e){
        keys.push(e.keyCode);
        
        if (keys.toString().indexOf(konami) >= 0) {
            window.location = '{$mybb->settings['bburl']}/couponcodes.php';
            keys = [];
        };
    }, true);
};
</script>

Voila, Konami Code implemented!

Who would use it?

Two word: Gaming Sites. I mean, you tell them about the Easter Egg, so why don't you demo it for them? Wink
Seems nice and works in 1.8, thanks.
Thw perfect Rick roll easter egg.
Can you get it to make an image pop up? If so how?
Replace:
window.location = '{$mybb->settings['bburl']}/couponcodes.php';

With anything you want to happen.

For instance:
$("#secret_modal").modal({fadeDuration:250,keepelement:!0});

And in my footer template:
<div id="secret_modal" style="display: none;">WAAAAA!</div> 

Or whatever you want to show.
(2015-03-16, 01:01 AM)Omar G. Wrote: [ -> ]Replace:

window.location = '{$mybb->settings['bburl']}/couponcodes.php';

With anything you want to happen.

For instance:

$("#secret_modal").modal({fadeDuration:250,keepelement:!0});

And in my footer template:

<div id="secret_modal" style="display: none;">WAAAAA!</div> 

Or whatever you want to show.

I want this to pop up where would I put the link in the code you provided and how would I do that?
I just told you.
(2015-03-16, 05:16 AM)Omar G. Wrote: [ -> ]I just told you.

So would I replace secret_modal with the link url?

Also whne I tried
<div id="secret_modal" style="display: none;">WAAAAA!</div>
/div> was orange.
Explain "orange" to me.
This

Also how do I use that modal thing and input the picture I want? I'm not really used to HTML or JS
Pages: 1 2