AFK macro

Toggle with F8, periodically sends keyboard inputs in to prevent AFK kicking

Você precisará instalar uma extensão como Tampermonkey, Greasemonkey ou Violentmonkey para instalar este script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

Você precisará instalar uma extensão como Tampermonkey ou Violentmonkey para instalar este script.

Você precisará instalar uma extensão como Tampermonkey ou Userscripts para instalar este script.

Você precisará instalar uma extensão como o Tampermonkey para instalar este script.

Você precisará instalar um gerenciador de scripts de usuário para instalar este script.

(Eu já tenho um gerenciador de scripts de usuário, me deixe instalá-lo!)

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

(Eu já possuo um gerenciador de estilos de usuário, me deixar fazer a instalação!)

// ==UserScript==
// @name         AFK macro
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Toggle with F8, periodically sends keyboard inputs in to prevent AFK kicking
// @author       Qwerty Matthew
// @match        https://minefun.io/*
// @match        https://*.minefun.io/*
// @match        http://minefun.io/*
// @match        http://*.minefun.io/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=minefun.io
// @grant        none
// @run-at       document-idle
// @license      ISC
// ==/UserScript==
// ==UserScript==

(function () {
    'use strict';

    let afkActive = false;
    let timerId = null;
    let notifyTimeout = null;

    // Create Screen Notification Overlay
    const notifyBox = document.createElement('div');
    notifyBox.style.position = 'fixed';
    notifyBox.style.bottom = '20px';
    notifyBox.style.left = '20px';
    notifyBox.style.padding = '10px 18px';
    notifyBox.style.borderRadius = '8px';
    notifyBox.style.fontWeight = 'bold';
    notifyBox.style.fontSize = '14px';
    notifyBox.style.fontFamily = 'sans-serif';
    notifyBox.style.color = '#ffffff';
    notifyBox.style.zIndex = '999999';
    notifyBox.style.display = 'none';
    notifyBox.style.opacity = '0';
    notifyBox.style.transition = 'opacity 0.2s ease';
    notifyBox.style.pointerEvents = 'none';
    document.body.appendChild(notifyBox);

    function showNotification(text, isActive) {
        if (notifyTimeout) {
            clearTimeout(notifyTimeout);
        }

        notifyBox.textContent = text;
        notifyBox.style.backgroundColor = isActive ? 'rgba(46, 204, 113, 0.85)' : 'rgba(231, 76, 60, 0.85)';
        notifyBox.style.display = 'block';

        setTimeout(() => {
            notifyBox.style.opacity = '1';
        }, 10);

        // Hide after 1.5 seconds
        notifyTimeout = setTimeout(() => {
            notifyBox.style.opacity = '0';
            setTimeout(() => {
                notifyBox.style.display = 'none';
            }, 200);
        }, 1500);
    }

    function getRandomInt(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    function scheduleNextAction() {
        if (!afkActive) return;
        const nextInterval = getRandomInt(30000, 45000);
        timerId = setTimeout(triggerAFKMovement, nextInterval);
    }

    function triggerAFKMovement() {
        if (!afkActive) return;

        const keyCode = Math.random() > 0.5 ? 'KeyW' : 'KeyS';
        const target = document.querySelector('canvas') || window;

        target.dispatchEvent(new KeyboardEvent('keydown', { code: keyCode, key: keyCode === 'KeyW' ? 'w' : 's', bubbles: true }));

        setTimeout(() => {
            target.dispatchEvent(new KeyboardEvent('keyup', { code: keyCode, key: keyCode === 'KeyW' ? 'w' : 's', bubbles: true }));
        }, getRandomInt(100, 200));

        if (Math.random() > 0.5) {
            setTimeout(() => {
                target.dispatchEvent(new KeyboardEvent('keydown', { code: 'Space', key: ' ', bubbles: true }));
                setTimeout(() => {
                    target.dispatchEvent(new KeyboardEvent('keyup', { code: 'Space', key: ' ', bubbles: true }));
                }, getRandomInt(80, 150));
            }, 250);
        }

        scheduleNextAction();
    }

    window.addEventListener('keydown', (e) => {
        if (document.activeElement && (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA')) {
            return;
        }

        if (e.key === 'F8') {
            e.preventDefault();
            afkActive = !afkActive;

            if (afkActive) {
                showNotification('AFK Macro: ACTIVE', true);
                scheduleNextAction();
            } else {
                showNotification('AFK Macro: OFF', false);
                clearTimeout(timerId);
            }
        }
    });
})();