Auto Farm (Pc)

Farmgod and send attack automatically at Loot Assistant at random intervals

目前為 2024-10-31 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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

})();