How to add konami code in a website based on html?

前端 未结 10 1293
野性不改
野性不改 2020-12-13 01:21

I was asked to implement the Konami Code in a website I\'m currently working on. It should do the following:

  1. Change Background Image

  2. Play s

10条回答
  •  遥遥无期
    2020-12-13 01:36

    I really liked Peter's answer, so I made it namespaced and made the callback optional. I also used jquery because I like it ¯\_(ツ)_/¯

    var Konami = Konami || {};
    
    Konami.key = '38384040373937396665';
    
    Konami.onCode = function(callback) {
        var input = '';
        $(document).on("keydown", function(e) {
            input += ("" + e.keyCode);
            if (input === Konami.key) {
                if(typeof callback == 'undefined') {
                    return alert("⬆⬆⬇⬇⬅➡⬅➡

提交回复
热议问题