Skip to content

callumlocke/cheet.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cheet.js

easy easter eggs in the browser

cheet('i d d q d', function () {
  alert('god mode enabled');
});
cheet('up up down down left right left right b a', {
  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

bower

bower install cheet.js

 

<script src="/bower_components/cheet.js/cheet.min.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, ...).

Available Key Names

NOTE: Key names are case-sensitive

Directionals

  • left
  • L (alias for left)
  • up
  • U (alias for up)
  • right
  • R (alias for right)
  • down
  • D (alias for down)

Alphanumeric

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

Misc

  • backspace
  • tab
  • enter
  • return (alias for enter)
  • shift
  • ctrl
  • alt
  • pause
  • capslock
  • esc
  • space
  • pageup
  • pagedown
  • end
  • home
  • insert
  • delete
  • equal
  • = (alias for equal)
  • comma
  • , (alias for comma)
  • minus
  • - (alias for minus)
  • period
  • . (alias for period)

Keypad

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

Function keys

  • f1-f12

TODO

Automated tests and travis-ci integration.

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%