Code Monkey home page Code Monkey logo

konami-komando's Introduction

Konami Komando

A simple JavaScript module that lets you pass a callback after a user has entered the Konami code.

Konami code

Install

npm install konami-komando --save-dev

Usage

require('konami-komando')({
  once: true,
  useCapture: true,
  callback: function() {
    // Do stuff here
  }
});

Parameters

once

Tells the code to only detect when a user has inputted the konami code once and then will no longer stop execution. If set to false, everytime the user inputs the konami code, the callback will be ran.

If not specified, it will default to true.

useCapture

Sets the priority of the event listener on keydown. This is important if you have your own event listeners on keydown. For more information on useCapture, check out this StackOverflow answer about it and also the MDN documentation.

If not specified, it will default to true.

callback

The action that should be ran after the konami code has been entered. If a function is not passed, it will throw an error.

konami-komando's People

Contributors

augbog avatar ryanburgess avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mylesborins

konami-komando's Issues

Find an intuitive way to pass function arguments for each key code

I can imagine there may be some interest in people who would want to pass a callback everytime a user successfully presses a konami code input to give a hint to the user that there is an easter egg.

Perhaps we could make it they pass an object/array of functions that will be executed each for their respective code input. Or make the module promise based somehow. Just throwing it out there.

Optimize konami code so that it actually will check if order is correct before final validation

Taking a look at the code

    // if first button isn't up, return
    if (keypresses.length == 0 && key != 38) {
      return;
    // if valid konami code character and keypresses available
    } else if (keypresses.length < 10 && /37|38|39|40|65|66/.test(key)) {

Ideally rather than validating a correct konami code character, it should verify if the order of the codes is entered correctly. The way it is now, if the user hits up and then hits any key that is a valid konami character i.e. up 10 times, it will still go through and try to validate. We can optimize it by simply going through a stack of the valid keypresses and fail the whole thing if its wrong.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.