Coder Social home page Coder Social logo

57u / cheet.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from namuol/cheet.js

0.0 2.0 0.0 792 KB

easy easter eggs (konami code, etc) for your website.

Home Page: http://namuol.github.io/cheet.js

License: MIT License

JavaScript 94.68% HTML 5.32%

cheet.js's Introduction

cheet.js Build Status dependency Status devDependency Status Gratipay Tips per Week

easy easter eggs in the browser

cheet('↑ ↑ ↓ ↓ ← → ← → b a', function () { alert('Voilà!'); });
cheet('i d d q d', function () {
  alert('god mode enabled');
});
cheet('o n e a t a t i m e', {
  next: function (str, key, num, seq) {
    console.log('key pressed: ' + key);
    console.log('progress: ' + num / seq.length);
    console.log('seq: ' + seq.join(' '));
  },

  fail: function () {
    console.log('sequence failed');
  },

  done: function () {
    console.log('+30 lives ;)');
  }
});
cheet('o n c e', function () {
  console.log('This will only fire once.');
  cheet.disable('o n c e');
});
var sequences = {
  cross: 'up down left right',
  circle: 'left up right down'
};

cheet(sequences.cross);
cheet(sequences.circle);

cheet.done(function (seq) {
  if (seq === sequences.cross) {
    console.log('cross!');
  } else {
    console.log('circle!');
  }
});

Demo

My personal site uses cheet.js (Try the Konami Code)

Install

Easy CDN

<script src="//cdn.rawgit.com/namuol/cheet.js/master/cheet.min.js" type="text/javascript"></script>

(Awesome free OSS hosting provided by @rgrove via rawgit)

bower

bower install cheet.js

<script src="/bower_components/cheet.js/cheet.js" type="text/javascript"></script>

component

component install namuol/cheet.js

<script src="/components/namuol-cheet.js/cheet.js" type="text/javascript"></script>

API

Map a sequence of keypresses to a callback. This can be called multiple times.

sequence (String)

A string representation of a sequence of key names.

Each keyname must be separated by a single space.

done(str, seq) (callback)

A callback to execute each time the sequence is correctly pressed.

Arguments:

  • str - The string representation of the sequence that completed.
  • seq - An array of key names representing the sequence that completed.

fail(str, seq) (callback)

A callback to execute each time a sequence's progress is broken.

Arguments:

  • str - The string representation of the sequence that failed.
  • seq - An array of key names representing the sequence that was pressed.

next(str, key, num, seq) (callback)

A callback to execute each time a correct key in the sequence is pressed in order.

Arguments:

  • str - The string representation of the sequence that is in progress.
  • key - The name of the key that was just pressed.
  • num - A number representing the current progress of the sequence. (starts at 0)
  • seq - An array of key names representing the sequence that is in progress.

Set a global callback that executes whenever any mapped sequence is completed successfully.

callback(str, seq) (callback)

A callback to execute each time any sequence is correctly pressed.

Arguments:

  • str - The string representation of the sequence that completed.
  • seq - An array of key names representing the sequence that completed.

Set a global callback that executes whenever any mapped sequence progresses.

callback(str, key, num, seq) (callback)

A callback to execute each time a correct key in any sequence is pressed in order.

Arguments:

  • str - The string representation of the sequence that is in progress.
  • key - The name of the key that was just pressed.
  • num - A number representing the current progress of the sequence. (starts at 0)
  • seq - An array of key names representing the sequence that is in progress.

Set a global callback that executes whenever any in-progress sequence is broken.

callback(str, seq) (callback)

A callback to execute each time any sequence's progress is broken.

Arguments:

  • str - The string representation of the sequence that failed.
  • seq - An array of key names representing the sequence that was pressed.

Disable a previously-mapped sequence.

sequence (String)

The same string you used to map the callback when using cheet(seq, ...).

Resets a sequence that may or may not be in progress.

This will not cause fail callbacks to fire, but will effectively cancel the sequence.

sequence (String)

The same string you used to map the callback when using cheet(seq, ...).

Available Key Names

NOTE: Key names are case-sensitive

Directionals

  • left | L |
  • up | U |
  • right | R |
  • down | D |

Alphanumeric

  • 0-9 (main number keys)
  • a-z

Misc

  • backspace
  • tab
  • enter | return
  • shift |
  • control | ctrl |
  • alt | option |
  • command |
  • pause
  • capslock
  • esc
  • space
  • pageup
  • pagedown
  • end
  • home
  • insert
  • delete
  • equal | =
  • comma | ,
  • minus | -
  • period | .

Keypad

  • kp_0-kp_9
  • kp_multiply
  • kp_plus
  • kp_minus
  • kp_decimal
  • kp_divide

Function keys

  • f1-f12

License

MIT

Testing

From the cheet.js' root directory:

grunt test

You can also run the tests directly in your browser:

grunt test.open

Or just view them online.

Acknowledgements

Special thanks to Guilherme J. Tramontina for writing the delicious mocha/chai test suite.


cheet.js was just a fun little one-night project I made to put easter eggs on my personal site.

If you're looking for something more useful/serious, check out Mousetrap.


Analytics

cheet.js's People

Contributors

namuol avatar gtramontina avatar callumlocke avatar

Watchers

James Cloos avatar Stuart avatar

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.