Aternos Auto-Start and Restart Bot

Start Aternos server and handle actions automatically.

当前为 2025-04-26 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Aternos Auto-Start and Restart Bot
// @namespace    https://aternos.org/
// @version      3.7
// @description  Start Aternos server and handle actions automatically.
// @author       Zephyr5929
// @match        https://aternos.org/server/*
// @grant        none
// @license      MIT
// @icon         https://media.forgecdn.net/avatars/375/55/637549609568691156.png
// ==/UserScript==

(function () {
    'use strict';
    const INITIAL_DELAY_MS = 10000;
    let startExecuted = false;
    let confirmSkipped = false;

    function onDOMReady(callback) {
        if (document.readyState === "complete" || document.readyState === "interactive") {
            callback();
        } else {
            document.addEventListener("DOMContentLoaded", callback);
        }
    }

    function isVisible(selector) {
        const element = document.querySelector(selector);
        return element && element.offsetParent !== null;
    }

    function clickElement(selector) {
        const element = document.querySelector(selector);
        if (element) {
            console.log(`Clicking element: ${selector}`);
            element.click();
            return true;
        } else {
            console.warn(`Element not found: ${selector}`);
            return false;
        }
    }

    function handleServerStart() {
        if (isVisible("#restart")) {
            console.log("'Restart' button is visible. Skipping 'Start' and 'Confirm now!' actions.");
            return;
        }
        if (isVisible("#start")) {
            console.log("'Start' button is visible. Starting the server...");
            if (clickElement("#start")) {
                startExecuted = true;
                monitorRestartOrConfirmButton();
            }
        } else {
            console.warn("'Start' button is not visible. No action taken.");
        }
    }

    function monitorRestartOrConfirmButton() {
        console.log("Monitoring for 'Restart' or 'Confirm now!' button...");
        const observer = new MutationObserver(() => {
            if (isVisible("#restart")) {
                console.log("'Restart' button detected. Skipping 'Confirm now!' and proceeding...");
                confirmSkipped = true;
                observer.disconnect();
            } else if (isVisible("#confirm")) {
                console.log("'Confirm now!' button detected. Clicking...");
                if (clickElement("#confirm")) {
                    observer.disconnect();
                }
            }
        });
        observer.observe(document.body, {
            childList: true,
            subtree: true,
        });
        setTimeout(() => observer.disconnect(), 30000);
    }

    onDOMReady(() => {
        console.log("Page loaded. Waiting 10 seconds before starting...");
        setTimeout(() => {
            handleServerStart();
        }, INITIAL_DELAY_MS);
    });
})();