项目作者: cm

项目描述 :
A utility function for observing Konami code input in a web browser. 👾
高级语言: JavaScript
项目地址: git://github.com/cm/konamify.git
创建时间: 2019-08-17T19:40:12Z
项目社区:https://github.com/cm/konamify

开源协议:MIT License

下载


Konamify

A utility function for observing Konami code input in a web browser.

Installation:

  1. npm install konamify

Or include the following script in your webpage:

  1. <script src="https://unpkg.com/konamify/konamify.min.js"></script>

Or it may be easier to just add the required code to your project manually. Simply paste the following:

  1. function konamify (cb) {
  2. var k = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65, 13], i = 0;
  3. window.addEventListener('keydown', function (e) {
  4. i = (e.keyCode === k[i]) ? i + 1 : 0;
  5. if (i === k.length) cb();
  6. });
  7. };

Example usage:

  1. konamify(function () {
  2. console.log('Konami code successfully entered!')
  3. })

How to:
In order to activate the konami code enter the following in a browser.

  1. UP UP DOWN DOWN LEFT RIGHT LEFT RIGHT B A ENTER