npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

konami-code-js

v0.8.1

Published

Fire a JavaScript Event when you enter the « Up Up Bottom Bottom Left Right Left Right B A » Konami Code Sequence.

Downloads

6,008

Readme

KonamiCodeJS

Fire a JavaScript Event when you enter the « Up Up Bottom Bottom Left Right Left Right B A » Konami Code Sequence with your keyboard. That work also when you do the following touch gesture « Up Up Bottom Bottom Left Right Left Right Tap Tap » with your finger.


Vous êtes français ? Le README derrière ce lien vous sera peut-être plus agréable.

Basic Usage

new KonamiCode(function () {
    // Do something here.
    // This part will be executed if « Up Up Down Down Left Right Left Right B A »
    // is recognised from Keyboard or Touch Gesture.
});

Custom Example

In this example, we will authorized only the area of <article> to listening Konami Code Sequence and after fire the Correct Sequence, avoid next Konami Code recognization.

var kc = new KonamiCode({
    listener: document.getElementsByTagName("article")[0]
});

kc.setCallback(function () {
    kc.disable();

    // Do something here.
    // This part will be executed if « Up Up Down Down Left Right Left Right B A »
    // is recognised from Keyboard or Touch Gesture.
});

API Documentation

Version: 0.8.1

Author: Bruno Lesieur

new KonamiCode([options])

Create Konami Code Sequence recognition « Up Up Bottom Bottom Left Right Left Right B A » on specific HTMLElement or on global HTMLDocument.

| Param | Type | Description | | --- | --- | --- | | [options] | Object | function | Container for all options. If type of options is Function, it is executed after Konami Code Sequence has been recognize. | | [options.callback] | function | If options is not a Function, options.callback is executed after Konami Code Sequence has been entered. The first parameter provided by the callback is current instance of KonamiCode. | | [options.listener] | Node | By default it is the HTMLDocument window.document. You can pass some HTMLElement like <input> (HTMLInputElement) to only recognize Konami Code Sequence from this element. | | [options.debug] | boolean | By default it is set to false. When you set this value to true, that allows you to see all debug message in the console. |

konamiCode.enable() ⇒ KonamiCode

Active the listening of Konami Code Sequence.

Kind: instance method of KonamiCode

Returns: KonamiCode - Current instance of KonamiCode

konamiCode.enableKeyboardKeys() ⇒ KonamiCode

Active the listening of Konami Code Sequence for Keyboard Keys.

Kind: instance method of KonamiCode

Returns: KonamiCode - Current instance of KonamiCode

konamiCode.enableTouchGesture() ⇒ KonamiCode

Active the listening of Konami Code Sequence for Touch Gesture.

Kind: instance method of KonamiCode

Returns: KonamiCode - Current instance of KonamiCode

konamiCode.disable() ⇒ KonamiCode

Unactive the listening of Konami Code Sequence.

Kind: instance method of KonamiCode

Returns: KonamiCode - Current instance of KonamiCode

konamiCode.disabledKeyboardKeys() ⇒ KonamiCode

Unactive the listening of Konami Code Sequence for Keyboard Keys.

Kind: instance method of KonamiCode

Returns: KonamiCode - Current instance of KonamiCode

konamiCode.disabledTouchGesture() ⇒ KonamiCode

Unactive the listening of Konami Code Sequence for Touch Gesture.

Kind: instance method of KonamiCode

Returns: KonamiCode - Current instance of KonamiCode

konamiCode.setListener(listener) ⇒ KonamiCode

Change the listener. The old listener will no longer work. Note: change the listener enable this instance if it is previously disable().

Kind: instance method of KonamiCode

Returns: KonamiCode - Current instance of KonamiCode

| Param | Type | Description | | --- | --- | --- | | listener | Node | You can pass some HTMLElement like <input> (HTMLInputElement) to only recognize Konami Code Sequence from this element. |

konamiCode.setCallback(callback) ⇒ KonamiCode

Change the Function executed after Konami Code Sequence has been entered.

Kind: instance method of KonamiCode

Returns: KonamiCode - Current instance of KonamiCode

| Param | Type | Description | | --- | --- | --- | | callback | function | Function executed after Konami Code Sequence has been entered. The first parameter provided by the callback is current instance of KonamiCode. |

Example

new KonamiCode().setCallback(function (konamiCode) {
    konamiCode.disable();
    // Do something here.
});

konamiCode.setOptions([options]) ⇒ KonamiCode

Change options of instance currently existing.

Kind: instance method of KonamiCode

Returns: KonamiCode - Current instance of KonamiCode

| Param | Type | Description | | --- | --- | --- | | [options] | Object | Container for all options. | | [options.callback] | function | Function executed after Konami Code Sequence has been entered. The first parameter provided by the callback is current instance of KonamiCode. | | [options.listener] | Node | By default it is the HTMLDocument window.document. You can pass some HTMLElement like <input> (HTMLInputElement) to only recognize Konami Code Sequence from this element. | | [options.debug] | boolean | By default it is set to false. When you set this value to true, that allows you to see all debug message in the console. |

KonamiCode.noConflict()

If a previous KonamiCode variable exist into global environment, you could kept it by changing name of current KonamiCode. You can also just use that function to change the name of Global « KonamiCode » variable.

Kind: static method of KonamiCode

Example

<script src="other/konami-code.js"></script>
<script src="last/konami-code.js"></script>
<script>
    var MyKC = KonamiCode.noConflict();
    console.log(KonamiCode); // Return the other KonamiCode
    console.log(MyKC); // Return your KonamiCode
</script>

KonamiCode.getNumberOfInstance() ⇒ number

Return the number of time KonamiCode was instanciated.

Kind: static method of KonamiCode

Returns: number - Number of KonamiCode instance create from begining.

Chaining

All API instanciated methods return the current instance of KonamiCode Object. That allows you to use instance like this.

new KonamiCode()
    .disable()
    .enable()
    .setListener(document.getElementsByTagName("body")[0])
    .setCallback(function (konamiCode) {
        konamiCode.disable();
        // Do something here.
        // This part will be executed if « Up Up Down Down Left Right Left Right B A »
        // is recognised from Keyboard or Touch Gesture.
    });

Debug Mode

You can see what step are used with console log message.

new KonamiCode({
    debug: true,
    callback: function (konamiCode) {
        konamiCode.disable();
    }
});

Import JavaScript File

By Direct Download

From NPM

npm install konami-code-js

From CDN

  • For development:
<script src="https://rawgit.com/Haeresis/konami-code-js/master/src/konami-code.js"></script>
  • For production:
<script src="https://cdn.rawgit.com/Haeresis/konami-code-js/master/src/konami-code.js"></script>

With AMD Loader

<script src="require.js"></script>
<script>
	requirejs(["konami-code"], function (KonamiCode) {
	    new KonamiCode(function () {
	    	// Do something here.
            // This part will be executed if « Up Up Down Down Left Right Left Right B A »
            // is recognised from Keyboard or Touch Gesture.
	    });
	});
</script>

With CommonJS Loader

var KonamiCode = require("konami-code-js");

new KonamiCode(function () {
    // Do something here.
    // This part will be executed if « Up Up Down Down Left Right Left Right B A »
    // is recognised from Keyboard or Touch Gesture.
});