SpaceAlpha Farm Plant Script (Auto Click)

Automatically sends a POST request to plant on SpaceAlpha's farm every 4 seconds.

  1. // ==UserScript==
  2. // @name SpaceAlpha Farm Plant Script (Auto Click)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description Automatically sends a POST request to plant on SpaceAlpha's farm every 4 seconds.
  6. // @author tt
  7. // @match https://spacealpha.net/train-units
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Function to send the POST request
  15. function sendPlantRequest(authToken) {
  16. const url = "https://spacealpha.net/api/planet/farm/plant";
  17.  
  18. fetch(url, {
  19. method: "POST",
  20. headers: {
  21. "Accept": "application/json",
  22. "Content-Type": "application/x-www-form-urlencoded",
  23. "Access-Control-Allow-Origin": "*",
  24. "x-access-token": authToken,
  25. "Cookies": "psd=false",
  26. "Origin": "https://spacealpha.net",
  27. "Referer": "https://spacealpha.net/train-units",
  28. "Sec-Fetch-Dest": "empty",
  29. "Sec-Fetch-Mode": "cors",
  30. "Sec-Fetch-Site": "same-origin",
  31. "DNT": "1",
  32. },
  33. body: "{}"
  34. })
  35. .then(response => {
  36. if (!response.ok) {
  37. console.error("Error sending request:", response.statusText);
  38. }
  39. return response.json();
  40. })
  41. .then(data => {
  42. console.log("Response data:", data);
  43. })
  44. .catch(error => {
  45. console.error("Fetch error:", error);
  46. });
  47. }
  48.  
  49. // Main logic to retrieve auth_token and trigger the request every 4 seconds
  50. const authToken = localStorage.getItem("auth_token");
  51. if (authToken) {
  52. console.log("Auth token found:", authToken);
  53.  
  54. // Send the first request immediately
  55. sendPlantRequest(authToken);
  56.  
  57. // Set up an interval to send the request every 4 seconds
  58. setInterval(() => {
  59. sendPlantRequest(authToken);
  60. }, 2234); // 2234 milliseconds = 2 seconds
  61. } else {
  62. console.error("No auth_token found in local storage.");
  63. }
  64. })();