Aternos Auto START Bot (Fixed)

Adds a working AutoStart button and auto-clicks Start/Confirm on Aternos.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Aternos Auto START Bot (Fixed)
// @namespace    https://www.lstv.ml
// @version      1.0.0
// @description  Adds a working AutoStart button and auto-clicks Start/Confirm on Aternos.
// @author       LSTV + fix
// @match        https://aternos.org/server/*
// @grant        none
// @run-at       document-idle
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    let botON = false;
    let loopTimer = null;
    let observer = null;

    function log(...args) {
        console.log('[Aternos AutoStart]', ...args);
    }

    function getServerActions() {
        return document.querySelector('.server-actions');
    }

    function getStartButton() {
        return document.querySelector('#start');
    }

    function getConfirmButton() {
        return document.querySelector('#confirm');
    }

    function getStatusBox() {
        return document.querySelector('.server-status .status') || document.querySelector('.status');
    }

    function isServerBusyOrOnline() {
        const actions = getServerActions();
        const statusBox = getStatusBox();

        if (!actions && !statusBox) return false;

        const actionClasses = actions ? actions.className : '';
        const statusClasses = statusBox ? statusBox.className : '';

        const combined = `${actionClasses} ${statusClasses}`.toLowerCase();

        return (
            combined.includes('online') ||
            combined.includes('loading') ||
            combined.includes('starting') ||
            combined.includes('queueing')
        );
    }

    function clickIfVisible(el) {
        if (!el) return false;
        if (el.disabled) return false;

        const style = window.getComputedStyle(el);
        if (style.display === 'none' || style.visibility === 'hidden') return false;

        el.click();
        return true;
    }

    function updateButton() {
        const btn = document.querySelector('#tm-autostart-btn');
        if (!btn) return;

        btn.textContent = botON ? 'AutoStart: ON' : 'AutoStart: OFF';
        btn.style.background = botON ? '#308fe3' : '#999999';
    }

    function tick() {
        if (!botON) return;

        try {
            if (!isServerBusyOrOnline()) {
                const confirmBtn = getConfirmButton();
                const startBtn = getStartButton();

                // Confirm first if present, then Start
                if (clickIfVisible(confirmBtn)) {
                    log('Clicked confirm');
                }

                if (clickIfVisible(startBtn)) {
                    log('Clicked start');
                }
            }
        } catch (err) {
            console.error('[Aternos AutoStart] Tick error:', err);
        }
    }

    function startLoop() {
        stopLoop();
        tick();
        loopTimer = setInterval(tick, 1200);
    }

    function stopLoop() {
        if (loopTimer) {
            clearInterval(loopTimer);
            loopTimer = null;
        }
    }

    function toggleBot() {
        botON = !botON;
        updateButton();

        if (botON) {
            log('Bot enabled');
            startLoop();
        } else {
            log('Bot disabled');
            stopLoop();
        }
    }

    function createButton() {
        if (document.querySelector('#tm-autostart-btn')) return;

        const actions = getServerActions();
        if (!actions) return;

        const btn = document.createElement('button');
        btn.id = 'tm-autostart-btn';
        btn.type = 'button';
        btn.textContent = 'AutoStart: OFF';

        btn.style.fontSize = '18px';
        btn.style.fontWeight = '700';
        btn.style.padding = '10px 16px';
        btn.style.marginTop = '10px';
        btn.style.marginLeft = '0';
        btn.style.border = 'none';
        btn.style.borderRadius = '6px';
        btn.style.cursor = 'pointer';
        btn.style.color = '#fff';
        btn.style.background = '#999999';
        btn.style.display = 'block';
        btn.style.width = '100%';
        btn.style.maxWidth = '260px';

        btn.addEventListener('click', toggleBot);

        actions.insertAdjacentElement('afterend', btn);
        updateButton();

        log('Button inserted');
    }

    function ensureUI() {
        createButton();
    }

    function initObserver() {
        if (observer) observer.disconnect();

        observer = new MutationObserver(() => {
            ensureUI();
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    }

    function init() {
        ensureUI();
        initObserver();
        log('Loaded');
    }

    if (document.readyState === 'loading') {
        window.addEventListener('DOMContentLoaded', init, { once: true });
    } else {
        init();
    }
})();