TrueBonus Auto Attack Random + Refresh

Auto login, random attack (5-10) and forced refresh every minute

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         TrueBonus Auto Attack Random + Refresh
// @namespace    https://truebonus.ru/
// @version      1.2
// @description  Auto login, random attack (5-10) and forced refresh every minute
// @author       Rubystance
// @license      MIT
// @match        https://truebonus.ru/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const EMAIL = "YOUR_EMAIL_HERE";
    const MIN_ATTACK = 5;
    const MAX_ATTACK = 10;
    const REFRESH_TIME = 60000; // 1 minute

    function randomAttackValue() {
        return Math.floor(Math.random() * (MAX_ATTACK - MIN_ATTACK + 1)) + MIN_ATTACK;
    }

    function waitFor(selector, callback, interval = 300) {
        const timer = setInterval(() => {
            const el = document.querySelector(selector);
            if (el) {
                clearInterval(timer);
                callback(el);
            }
        }, interval);
    }

    function forceRefreshLoop() {
        setTimeout(() => {
            location.reload();
        }, REFRESH_TIME);
    }

    if (location.pathname === "/" || location.pathname === "/index.php") {
        waitFor('input[name="email"]', (input) => {
            const form = input.closest('form');
            const button = form?.querySelector('button[type="submit"]');

            input.focus();
            input.value = EMAIL;
            input.dispatchEvent(new Event('input', { bubbles: true }));
            input.dispatchEvent(new Event('change', { bubbles: true }));

            if (button) {
                setTimeout(() => button.click(), 500);
            }
        });
    }

    if (location.pathname === "/dashboard") {

        waitFor('#attack-btn', (attackBtn) => {

            const tryAttack = () => {
                const match = attackBtn.innerText.match(/\d+/);
                if (!match) return;

                const currentEnergy = parseInt(match[0], 10);
                const attackCost = randomAttackValue();

                if (
                    currentEnergy >= attackCost &&
                    !attackBtn.disabled
                ) {
                    attackBtn.innerText = `Attack (${attackCost})`;
                    attackBtn.click();
                }
            };

            tryAttack();

            const observer = new MutationObserver(tryAttack);
            observer.observe(attackBtn, {
                childList: true,
                subtree: true,
                characterData: true,
                attributes: true
            });

            forceRefreshLoop();
        });
    }

})();