×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Konami code help
3

Konami code help

Konami code help

(OP)
I would love to enter a konami code on one of our websites, whereby entering a key combination will blur the screen, entering again will blur even more, entering for a third time redirects to our safe drinking page.

I have found a konami code script at https://codepen.io/ultraschaller/pen/jPPQRq which seems great, however my boss doesn't want to use the konami code (boooo), instead he wants the word 'drink'.

There are two questions,

1. how do I find out the keys for d r i n k to replace up up down down etc
2. to blur the whole page fir the first time, I'll set

body {
filter: blur(2px);
}

on the second time the text is entered, I'd like to double this to

body {
filter: blur(4px);
}

and for the third time, redirect to another page on our website.

How do I modify the javascript to do this?

Thanks for any help

RE: Konami code help

First of all: LOL!
Secondly: https://www.cambiaresearch.com/articles/15/javascr...

winky smile

Oh, for point 2): You could try with a cookie as counter. A simple if / switch case should suffice for the rest.

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

RE: Konami code help

Hi

Quote (tyutghf)

1. how do I find out the keys for d r i n k to replace up up down down etc
Open your browser's Console and type :

CODE --> JavaScript

'drink'.split('').map(c => c.toUpperCase().charCodeAt()) 

Quote (tyutghf)

How do I modify the javascript to do this?
Use a counter variable to keep track of drinks then use conditional statement to do either one or other action :

CODE --> JavaScript

var keys = [];
var konami = '68,82,73,78,75';
var count = 0;

$(document).keydown(function(e) {
    keys.push(e.keyCode);
    if (keys.toString().indexOf(konami) >=0) {
        keys = [];
        if (++count == 3)
            location.href = 'https://example.com/';
        else
            $('body').css('filter', `blur(${ count * 2 }px)`);
    }
}); 


Feherke.
feherke.github.io

RE: Konami code help

(OP)
Awesome, thanks for the help

RE: Konami code help

(OP)
Oh dear, my boss loves it and wants another.

Can I add a redirect for another set of keys? If the user types in 'offer', it redirects to a hidden page on the website.

Thnks

RE: Konami code help

Hi

Quote (tyutghf)

redirects to a hidden page
Is your boss aware that we are talking about client side scripting ? So the JavaScript source code will contain the page's name, so will not be so hidden anymore.

Beside that, what should happen if the visitor types "drink" twice then "offer" once ? Will that act as 1st interaction and lower the blur back to 2px ( although the 2nd "drink" already set it to 4px ) or will act as 3rd interaction and redirect to the hidden page ( although "offer" was only typed in once ) ?

Feherke.
feherke.github.io

RE: Konami code help

(OP)
It's only hidden as far as not visible on the site navigation and hidden to robots. he is happy for anyone to view it if it gives him more sales.

offer should direct the user to the 'hidden' page, so take them away from whatever they were doing anyway. I can place a 'go back' button on the hidden page so they can resume what page they were browsing.

the redirect on drink needs to stay in place if they type drink three times

RE: Konami code help

Hi

You did not answered the question aimed to clarify whether "drink" and "offer" should be counted together or separately.

Quote (tyutghf)

the redirect on drink needs to stay in place if they type drink three times
Does that mean, if the visitor enters "drink" twice, then "offer" enough times to visit the hidden page, then navigate back, then entering "drink" one more time should directly redirect to the non-hidden page ? Then a cookie will be needed as MakeItSo suggested, which complicates abit both the theory and the implementation.

Feherke.
feherke.github.io

RE: Konami code help

(OP)
The two should work independently of each other ideally.

scenarios
Type drink - blur 2px
Type drink - blur 4px
type drink - redirect to the drink awareness page

type offer - redirect to the offer page

type drink - blur 2px
type offer - redirect to the offer page

Does that make sense?

We don't need it to carry across the site, so they type drink on the homepage which blurs the page. If they navigate away, the page is back to normal. They can type drink again, this will blur 2px the new page etc. If they blur 4px and can;t navigate, a page refresh will bring it back to normal.

RE: Konami code help

Hi

Ah, so the "offer" redirects immediately ? Then maybe would be place for abit more flexibility :

CODE --> JavaScript

var konami = {
  'drink': {'need': 3, 'url': 'https://example.com/'},
  'offer': {'url': 'hidden-page.html'},
};
var keys = '';

$(document).keydown(function(e) {
    keys += e.key;
    for (var word in konami)
        if (keys.indexOf(word) >= 0) {
            keys = '';
            konami[word].count = (konami[word].count || 0) + 1;
            if (konami[word].count == (konami[word].need || 1))
                location.href = konami[word].url;
            else
                $('body').css('filter', `blur(${ konami[word].count * 2 }px)`);
        }
}); 
I guess you got the point :
  • Enumerate in the konami object all actions, with the trigger word as key
  • For each trigger word specify its own URL to redirect to
  • Optionally for trigger words which not redirect immediately specify the count with the need keyword
Note that trigger word checking is case sensitive ( "Drink" != "drink" ).

Feherke.
feherke.github.io

RE: Konami code help

(OP)
That's awesome thanks

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close