Fake bot Change Villa

Change villa every iteration

目前為 2025-01-19 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Fake bot Change Villa
// @version      1
// @description  Change villa every iteration
// @include      https://*/game.php*screen=place*
// @namespace https://gf.qytechs.cn/users/1388863
// ==/UserScript==

(function() {
    'use strict';

    // Create Start/Stop button
    const startStopButton = document.createElement('button');
    startStopButton.textContent = 'Start';
    startStopButton.style.position = 'fixed';
    startStopButton.style.bottom = '20px';
    startStopButton.style.right = '20px';
    startStopButton.style.padding = '10px 20px';
    startStopButton.style.fontSize = '16px';
    startStopButton.style.backgroundColor = '#4CAF50';
    startStopButton.style.color = 'white';
    startStopButton.style.border = 'none';
    startStopButton.style.borderRadius = '5px';
    startStopButton.style.cursor = 'pointer';
    startStopButton.style.zIndex = '9999';
    document.body.appendChild(startStopButton);

    // Create Loop Count button
    const loopButton = document.createElement('button');
    loopButton.textContent = 'Set Loops';
    loopButton.style.position = 'fixed';
    loopButton.style.bottom = '20px';
    loopButton.style.right = '120px';
    loopButton.style.padding = '10px 20px';
    loopButton.style.fontSize = '16px';
    loopButton.style.backgroundColor = '#FF9800';
    loopButton.style.color = 'white';
    loopButton.style.border = 'none';
    loopButton.style.borderRadius = '5px';
    loopButton.style.cursor = 'pointer';
    loopButton.style.zIndex = '9999';
    document.body.appendChild(loopButton);

    // Create remaining loop counter display
    const loopCounterDisplay = document.createElement('div');
    loopCounterDisplay.style.position = 'fixed';
    loopCounterDisplay.style.bottom = '70px';
    loopCounterDisplay.style.right = '20px';
    loopCounterDisplay.style.fontSize = '18px';
    loopCounterDisplay.style.color = 'white';
    loopCounterDisplay.style.zIndex = '9999';
    loopCounterDisplay.textContent = 'Remaining Loops: 0';
    document.body.appendChild(loopCounterDisplay);

    // Retrieve the last state from localStorage
    let isRunning = localStorage.getItem('botState') === 'running';
    let remainingLoops = parseFloat(localStorage.getItem('remainingLoops')) || 0;
    let currentloop = parseFloat(localStorage.getItem('currentloop')) || remainingLoops;

    // Set initial button and loop counter state
    startStopButton.textContent = isRunning ? 'Stop' : 'Start';
    loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;

    // Start the bot if it was running
    if (isRunning) {
        startBot();
    }

    // Start/Stop button event
    startStopButton.addEventListener('click', () => {
        if (isRunning) {
            stopBot();
        } else {
            startBot();
        }
    });

    // Loop button event
    loopButton.addEventListener('click', () => {
        const loopsInput = parseInt(prompt("Enter the number of loops to run:", remainingLoops), 10);
        if (!isNaN(loopsInput) && loopsInput > 0) {
            remainingLoops = loopsInput;
            currentloop = remainingLoops;
            localStorage.setItem('remainingLoops', remainingLoops);
            localStorage.setItem('currentloop', currentloop);
            loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
            console.log(`Set loops to: ${remainingLoops}`);
        }
    });

    function startBot() {
        isRunning = true;
        localStorage.setItem('botState', 'running');
        startStopButton.textContent = 'Stop';
        console.log("Bot started");
        loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
        runBotLoop();
    }

    function stopBot() {
        isRunning = false;
        localStorage.setItem('botState', 'stopped');
        startStopButton.textContent = 'Start';
        console.log("Bot stopped");
    }

    function runBotLoop() {
        if (remainingLoops > 0) {
            if (!window.location.href.includes("&screen=place&try=confirm")) {
                if (currentloop !== remainingLoops) {
                    setTimeout(() => {
                        clickKeyD(() => {
                            console.log("Clicked key 'D' and resuming...");
                        });
                        currentloop = remainingLoops;
                        localStorage.setItem('currentloop', currentloop);
                    }, 300 + Math.random() * 200);
                }
                setTimeout(() => {
                    document.dispatchEvent(new KeyboardEvent('keydown', {
                        key: '0', code: 'Digit0', keyCode: 48, which: 48, bubbles: true
                    }));
                    console.log("Key '0' pressed.");

                    setTimeout(() => {
                        const attackButton = document.getElementById("target_attack");
                        if (attackButton) {
                            attackButton.click();
                            console.log("Clicked target_attack button.");
                        } else {
                            console.log("Button with ID 'target_attack' not found.");
                        }
                    }, 500 + Math.random() * 300);
                }, 1000 + Math.random() * 300);
            }

            setTimeout(() => {
                const url = window.location.href;
                if (url.includes("&screen=place&try=confirm")) {
                    const confirmButton = document.querySelector('#troop_confirm_submit');
                    if (confirmButton) {
                        console.log("Detected &screen=place&try=confirm and #troop_confirm_submit exists");
                        // setTimeout(()=> clickButton('#troop_confirm_submit', Math.random() * 100 + 100), 100);
                        setTimeout(() => {
                            clickButton('#troop_confirm_submit')
                        }, 200 + Math.random() * 100);
                        remainingLoops -= 1;
                        localStorage.setItem('remainingLoops', remainingLoops);
                        localStorage.setItem('currentloop', currentloop);
                        loopCounterDisplay.textContent = `Remaining Loops: ${remainingLoops}`;
                        console.log("Sent confirmation");
                    } else {
                        // const newUrl = url.replace("&try=confirm", "");
                        // window.location.href = newUrl;
                        currentloop -= 1;
                        localStorage.setItem('currentloop', currentloop);
                        const newUrl = url.replace(/(&screen=place).*$/, "$1");
                        window.location.href = newUrl;

                    }
                }

                if (remainingLoops > 0) {
                    runBotLoop();
                } else {
                    stopBot();
                }
            }, 700 + Math.random() * 300);
        }
    }

    function clickKeyD(callback) {
        setTimeout(() => {
            document.dispatchEvent(new KeyboardEvent('keydown', {
                key: 'D', code: 'KeyD', keyCode: 68, which: 68, bubbles: true
            }));
            console.log("Key 'D' pressed.");
            if (callback) callback();
        }, Math.random() * 200 + 100);
    }

    // function clickButton(selector, delay) {
    //     const button = document.querySelector(selector);
    //     if (button) {
    //         setTimeout(() => button.click(), delay);
    //         console.log(`Button clicked after ${delay}ms`);
    //     } else {
    //         console.log("Button not found!");
    //     }
    // }

    function clickButton(selector) {
        const button = document.querySelector(selector);
        if (button) {
            console.log(`Button clicked`);
            button.click()
        } else {
            console.log("Button not found!");
        }
    }

})();

QingJ © 2025

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