Aternos Auto START Bot (Fixed)

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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