Auto Farm (Pc)

Farmgod and send attack automatically at Loot Assistant at random intervals

目前为 2024-10-31 提交的版本。查看 最新版本

// ==UserScript==
// @name         Auto Farm (Pc)
// @version      1.2
// @description  Farmgod and send attack automatically at Loot Assistant at random intervals
// @include      https://*/game.php*screen=am_farm*
// @namespace https://gf.qytechs.cn/users/1388863
// ==/UserScript==

(function () {
    'use strict';

    // Create toggle button
    let button = document.createElement("button");
    button.innerText = "Stop";
    button.style.position = "fixed";
    button.style.bottom = "40px";
    button.style.left = "20px";
    button.style.padding = "8px 15px";
    button.style.fontSize = "14px";
    button.style.zIndex = "1000";
    button.style.backgroundColor = "#4CAF50";
    button.style.color = "white";
    button.style.border = "none";
    button.style.borderRadius = "5px";
    button.style.cursor = "pointer";
    document.body.appendChild(button);

    // Create countdown box
    let countdownPopup = document.createElement("div");
    countdownPopup.style.position = "fixed";
    countdownPopup.style.bottom = "75px";
    countdownPopup.style.left = "20px";
    countdownPopup.style.padding = "8px 15px";
    countdownPopup.style.fontSize = "14px";
    countdownPopup.style.zIndex = "1000";
    countdownPopup.style.backgroundColor = "#333";
    countdownPopup.style.color = "white";
    countdownPopup.style.borderRadius = "5px";
    countdownPopup.style.display = "none";
    document.body.appendChild(countdownPopup);

    let isRunning = true;
    let intervalId;
    let countdownInterval;

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

    function pressEnterRandomly() {
        const delay = randomDelay(200, 350);
        document.dispatchEvent(new KeyboardEvent('keydown', {
            key: 'Enter',
            code: 'Enter',
            which: 13,
            keyCode: 13,
            bubbles: true
        }));
        intervalId = setTimeout(pressEnterRandomly, delay);
    }

    function loadFarmGodScript() {
        $.getScript('https://higamy.github.io/TW/Scripts/Approved/FarmGodCopy.js')
            .done(function (script, textStatus) {
                console.log('Script loaded successfully:', textStatus);
            })
            .fail(function (jqxhr, settings, exception) {
                console.error('Error loading script:', exception);
            });
    }

    function clickOptionButton(retries = 3) {
        let button = document.querySelector('input.btn.optionButton[value="Plan farms"]');
        if (button) {
            button.click();
            console.log("Button 'Plan farms' clicked");
        } else {
            console.log("Button 'Plan farms' not found");
            if (retries > 0) {
                console.log("Retrying...");
                setTimeout(function () {
                    clickOptionButton(retries - 1);
                }, randomDelay(2000, 4000));
            }
        }
    }

    function startProcess() {
        setTimeout(() => {
            loadFarmGodScript();
            setTimeout(() => {
                clickOptionButton();
                setTimeout(() => {
                    pressEnterRandomly();
                    startCountdown();
                }, randomDelay(1000, 5000));
            }, randomDelay(1000, 5000));
        }, randomDelay(1000, 5000));
    }

    function stopProcess() {
        clearTimeout(intervalId);
        clearInterval(countdownInterval);
        button.innerText = "Start";
        countdownPopup.style.display = "none";
        isRunning = false;
    }

    function toggleProcess() {
        if (isRunning) {
            stopProcess();
        } else {
            startProcess();
            button.innerText = "Stop";
            isRunning = true;
        }
    }

    function startCountdown() {
        let timeLeft = randomDelay(300, 900);
        countdownPopup.style.display = "block";
        countdownInterval = setInterval(() => {
            if (timeLeft <= 0) {
                clearInterval(countdownInterval);
                countdownPopup.style.display = "none";
                location.reload();
            } else {
                countdownPopup.innerText = `Next loop in: ${Math.floor(timeLeft / 60)}m ${timeLeft % 60}s`;
                timeLeft--;
            }
        }, 1000);
    }

    startProcess();

    button.addEventListener("click", toggleProcess);

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址