save time to click

Adding button to save your time

当前为 2025-02-18 提交的版本,查看 最新版本

// ==UserScript==
// @name         save time to click
// @namespace    http://tampermonkey.net/
// @version      0.0.1
// @description  Adding button to save your time
// @match        https://www.edominacy.com/*/battlefield/*/*
// @grant        none
// @license MIT free to use
// ==/UserScript==

(function () {
    const PREFIX = {
        NAVY: "a#battleWeapons_25_",
        TANK: "a#battleWeapons_26_",
        SPECIAL_WEAPON: "a#battleWeapons_32_5"  // Special weapon selector
    };

    // Weapon quality management class
    const weaponQualityManager = new class {
        #quality = 5; // Start with quality 5
        #isInitial = true; // Initial state (True = First state, False = After first click)

        // Select the next quality
        pickNextQuality(callback) {
            if (this.#quality > 1) {
                this.#quality--; // Decrease quality if not at minimum
            } else {
                callback(); // If quality reaches 1, callback is executed (can be stop logic)
            }
        }

        // Get the current quality
        getCurrentQuality() {
            return this.#quality;
        }

        // Check if we are in the initial state
        isInitial() {
            return this.#isInitial;
        }

        // Reset to initial quality
        reset() {
            this.#quality = 5;
            this.#isInitial = true;
        }
    };

    function getProfileId() {
        const profileLink = document.querySelector("ul.dropdown-menu a[href*='/en/profile/']");
        if (profileLink) {
            const href = profileLink.href;
            const profileId = href.split("/").pop(); // Extract the number after /profile/
            console.log("Profile ID found:", profileId);
            return profileId;
        } else {
            console.log("Profile link not found!");
            return null;
        }
    }

    // Select a weapon based on the quality passed
    function selectWeapon(quality) {
        let weapon = document.querySelector(`${PREFIX.TANK}${quality}`);
        if (!weapon) {
            weapon = document.querySelector(`${PREFIX.NAVY}${quality}`);
        }
        return weapon;
    }

    // Check if the special weapon is available
    function checkSpecialWeapon() {
        const specialWeapon = document.querySelector(PREFIX.SPECIAL_WEAPON);
        if (specialWeapon && !specialWeapon.classList.contains('disabled')) {
            console.log("Special weapon is available for use.");
            return specialWeapon;
        }
        console.log("Special weapon is not available.");
        return null;
    }

    function fighter({ button, icon, clearParentInterval }) {
        console.log("Starting fighter interval...");
        const intervalId = setInterval(() => {
            console.log("Interval running...");

            const energy = document.getElementById("energyBarT");
            if (!energy) {
                console.log("Energy bar not found!");
                return;
            }

            const numberEnergy = Number.parseInt(energy.innerText);
            console.log(`Energy: ${numberEnergy}`);

            const energyBar = document.getElementById("battleEnergy");
            const countDown = document.querySelector(".countdown_row.countdown_amount");
            const profileId = getProfileId(); // Get profile ID
            if (!profileId) {
                console.log("Profile ID not found, stopping...");
                return;
            }

            const fightButton = document.getElementById(`battleFight${profileId}`);
            if (!fightButton) {
                console.log("Fight button not found for profile ID:", profileId);
                return;
            }

            if (!countDown || countDown.innerText === "00:00:00" || countDown < "00:00:03") {
                console.log("Countdown ended or near zero, stopping...");
                if (fightButton) {
                    fightButton.innerText = "FIGHT";
                }

                restoreDefaultButtonState({ button, icon });
                clearParentInterval();
                console.info("STOPPED");
                return;
            }

            fightButton.innerText = "CLICKING";

            let weapon = null;

            // Check for special weapon first
            weapon = checkSpecialWeapon();
            if (!weapon) {
                // If special weapon is not available, fall back to normal weapon selection
                if (weaponQualityManager.isInitial()) {
                    console.log("Weapon not selected yet...");
                    weapon = selectWeapon(weaponQualityManager.getCurrentQuality()); // First check for quality 5
                    if (!weapon) {
                        console.log("No weapon found for quality 5. Trying quality 4...");
                        weaponQualityManager.pickNextQuality(() => {
                            console.log("No weapon found for quality 4, stopping...");
                            restoreDefaultButtonState({ button, icon });
                            clearParentInterval();
                        });
                        weapon = selectWeapon(weaponQualityManager.getCurrentQuality()); // Try quality 4
                    }

                    if (weapon) {
                        console.log(`Weapon found for quality ${weaponQualityManager.getCurrentQuality()}, selecting...`);
                        // Click the selected weapon
                        weapon.click();
                    }
                }
            } else {
                // Special weapon found, use it
                weapon.click();
            }

            if (numberEnergy < 1001) {
                console.log("Energy less than 1001, trying to click energy bar...");
                if (!energyBar) {
                    console.log("Energy bar not found to click!");
                    fightButton.innerText = "FIGHT";
                    restoreDefaultButtonState({ button, icon });
                    clearParentInterval();
                    console.info("STOPPED NO MORE ENERGY");
                    return;
                }

                energyBar.click();
            } else {
                console.log("Energy sufficient, clicking fight button...");
                fightButton.click();
            }
        }, 2_500);

        return intervalId;
    }

    function restoreDefaultButtonState({ button, icon }) {
        console.log("Restoring default button state...");
        icon.className = "fa fa-fighter-jet";
        button.className = "btn btn-success";
        button.blur();
    }

    function appendChildrenToVs919() {
        console.log("Appending start/stop button to VS919 container...");
        const container = document.querySelector("div.vs919");
        if (!container) {
            console.log("VS919 container not found!");
            return;
        }

        container.style.display = "flex";
        const startStopButton = document.createElement("button");
        startStopButton.title = "Fight";
        startStopButton.className = "btn btn-success";

        const icon = document.createElement("i");
        icon.className = "fa fa-fighter-jet";
        icon.style.pointerEvents = "none";
        startStopButton.appendChild(icon);

        let interval = null;
        startStopButton.addEventListener("click", (e) => {
            console.log("Start/Stop button clicked...");

            if (interval) {
                console.log("Stopping interval...");
                restoreDefaultButtonState({
                    button: e.target,
                    icon
                });
                clearInterval(interval);
                interval = null;
                return;
            }

            console.log("Starting interval...");
            icon.className = "fa fa-pause";
            e.target.className = "btn btn-info";
            e.target.blur();
            interval = fighter({
                button: e.target,
                icon,
                clearParentInterval: () => {
                    console.log("Clearing parent interval...");
                    clearInterval(interval);
                    interval = null;
                }
            });
        });

        container.appendChild(startStopButton);
    }

    appendChildrenToVs919();
})();

QingJ © 2025

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