Auto Farm (Pc)

Farmgod and send attack automatically at Loot Assistant at random intervals

ของเมื่อวันที่ 31-10-2024 ดู เวอร์ชันล่าสุด

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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://greasyfork.org/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);

})();