Aternos Auto-Start and Restart Bot

Start Aternos server and handle actions automatically.

  1. // ==UserScript==
  2. // @name Aternos Auto-Start and Restart Bot
  3. // @namespace https://aternos.org/
  4. // @version 3.7
  5. // @description Start Aternos server and handle actions automatically.
  6. // @author Zephyr5929
  7. // @match https://aternos.org/server/*
  8. // @grant none
  9. // @license MIT
  10. // @icon https://media.forgecdn.net/avatars/375/55/637549609568691156.png
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. const INITIAL_DELAY_MS = 10000;
  16. let startExecuted = false;
  17. let confirmSkipped = false;
  18.  
  19. function onDOMReady(callback) {
  20. if (document.readyState === "complete" || document.readyState === "interactive") {
  21. callback();
  22. } else {
  23. document.addEventListener("DOMContentLoaded", callback);
  24. }
  25. }
  26.  
  27. function isVisible(selector) {
  28. const element = document.querySelector(selector);
  29. return element && element.offsetParent !== null;
  30. }
  31.  
  32. function clickElement(selector) {
  33. const element = document.querySelector(selector);
  34. if (element) {
  35. console.log(`Clicking element: ${selector}`);
  36. element.click();
  37. return true;
  38. } else {
  39. console.warn(`Element not found: ${selector}`);
  40. return false;
  41. }
  42. }
  43.  
  44. function handleServerStart() {
  45. if (isVisible("#restart")) {
  46. console.log("'Restart' button is visible. Skipping 'Start' and 'Confirm now!' actions.");
  47. return;
  48. }
  49. if (isVisible("#start")) {
  50. console.log("'Start' button is visible. Starting the server...");
  51. if (clickElement("#start")) {
  52. startExecuted = true;
  53. monitorRestartOrConfirmButton();
  54. }
  55. } else {
  56. console.warn("'Start' button is not visible. No action taken.");
  57. }
  58. }
  59.  
  60. function monitorRestartOrConfirmButton() {
  61. console.log("Monitoring for 'Restart' or 'Confirm now!' button...");
  62. const observer = new MutationObserver(() => {
  63. if (isVisible("#restart")) {
  64. console.log("'Restart' button detected. Skipping 'Confirm now!' and proceeding...");
  65. confirmSkipped = true;
  66. observer.disconnect();
  67. } else if (isVisible("#confirm")) {
  68. console.log("'Confirm now!' button detected. Clicking...");
  69. if (clickElement("#confirm")) {
  70. observer.disconnect();
  71. }
  72. }
  73. });
  74. observer.observe(document.body, {
  75. childList: true,
  76. subtree: true,
  77. });
  78. setTimeout(() => observer.disconnect(), 30000);
  79. }
  80.  
  81. onDOMReady(() => {
  82. console.log("Page loaded. Waiting 10 seconds before starting...");
  83. setTimeout(() => {
  84. handleServerStart();
  85. }, INITIAL_DELAY_MS);
  86. });
  87. })();

QingJ © 2025

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