コナミコマンドをWebで
なんとなくこんなの作った。
var KeyCommand = Class.create(); KeyCommand.prototype = { initialize: function() { this.map = []; this.key_history = ''; Event.observe(document, 'keyup', this.observer.bind(this)); }, observer: function (event) { this.key_history += "/" + event.keyCode; for(i=0, len=this.map.length; i < len; i++) { if (this.key_history.indexOf(this.map[i].command) > -1) { this.map[i].callback(); this.key_history = ""; } } }, set_command: function (command, callback) { this.map.push({ command: command, callback: callback }); } }
HTMLのほうに、↓みたいなのを仕込むとコナミコマンドでfunctionを実行できる。
用途は不明。
var cmd = new KeyCommand; cmd.set_command("/38/38/40/40/37/39/37/39/66/65", callback); cmd.set_command("/38/38/40/40/76/82/76/82/66/65", callback);
追記 ちなみにprototype.js必須