AFK macro

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

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==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);
            }
        }
    });
})();