Greasy Fork

魂斗罗30命

自动输入"上上下下左右左右BABA"

当前为 2023-04-09 提交的版本,查看 最新版本

// ==UserScript==
// @name         魂斗罗30命
// @namespace    
// @license MIT
// @version      1.0
// @description  自动输入"上上下下左右左右BABA"
// @author       CHATPGT
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    
    const konamiCode = 'ArrowUpArrowUpArrowDownArrowDownArrowLeftArrowRightArrowLeftArrowRightba';
    
    function triggerKonamiCode() {
        let event;
        let i = 0;
        
        const triggerKey = function(key) {
            event = new KeyboardEvent('keydown', {'key': key});
            document.dispatchEvent(event);
        };
        
        const triggerCode = function() {
            if (i < konamiCode.length) {
                triggerKey(konamiCode[i]);
                i++;
                setTimeout(triggerCode, 100);
            }
        };
        
        triggerCode();
    }
    
    const button = document.createElement('button');
    button.innerText = 'Konami Code';
    button.onclick = triggerKonamiCode;
    document.body.appendChild(button);
})();