Web3TestApiAgnt.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. // ==UserScript==
  2. // @name AGNT.Hub Task Automation
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Automate AGNT.Hub tasks using current page's Cookie and Headers
  6. // @author Jack
  7. // @match https://quests.agnthub.ai/*
  8. // @grant GM_xmlhttpRequest
  9. // @connect hub-api.agnthub.ai
  10. // @connect quests.agnthub.ai
  11. // ==/UserScript==
  12. (function () {
  13. "use strict";
  14. const executeButton = document.createElement("button");
  15. executeButton.textContent = "恶魔城,启动!!";
  16. executeButton.style.position = "fixed";
  17. executeButton.style.top = "20px";
  18. executeButton.style.left = "50%";
  19. executeButton.style.padding = "10px 20px";
  20. executeButton.style.backgroundColor = "#007bff";
  21. executeButton.style.color = "#fff";
  22. executeButton.style.border = "none";
  23. executeButton.style.borderRadius = "5px";
  24. executeButton.style.cursor = "pointer";
  25. executeButton.style.zIndex = "10000";
  26. executeButton.addEventListener("click", function () {
  27. const currentCookie = document.cookie;
  28. const responses = [];
  29. const tasks = [
  30. {
  31. url: "https://hub-api.agnthub.ai/api/daily-rewards/claim",
  32. headers: {
  33. "accept": "application/json, text/plain, */*",
  34. "accept-encoding": "gzip, deflate, br, zstd",
  35. "accept-language": "zh-CN,zh;q=0.9",
  36. "content-length": "0",
  37. "cookie": currentCookie,
  38. "origin": "https://quests.agnthub.ai",
  39. "priority": "u=1, i",
  40. "referer": "https://quests.agnthub.ai/",
  41. "sec-ch-ua": '"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"',
  42. "sec-ch-ua-mobile": "?0",
  43. "sec-ch-ua-platform": '"Windows"',
  44. "sec-fetch-dest": "empty",
  45. "sec-fetch-mode": "cors",
  46. "sec-fetch-site": "same-site",
  47. "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
  48. }
  49. },
  50. {
  51. url: "https://hub-api.agnthub.ai/api/tasks/make-ai-laugh/34ecad1e-94df-48ba-b5f4-242fdd9d6546",
  52. headers: {
  53. "accept": "application/json, text/plain, */*",
  54. "accept-encoding": "gzip, deflate, br, zstd",
  55. "accept-language": "zh-CN,zh;q=0.9",
  56. "content-length": "0",
  57. "cookie": currentCookie,
  58. "origin": "https://quests.agnthub.ai",
  59. "priority": "u=1, i",
  60. "referer": "https://quests.agnthub.ai/",
  61. "sec-ch-ua": '"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"',
  62. "sec-ch-ua-mobile": "?0",
  63. "sec-ch-ua-platform": '"Windows"',
  64. "sec-fetch-dest": "empty",
  65. "sec-fetch-mode": "cors",
  66. "sec-fetch-site": "same-site",
  67. "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
  68. }
  69. }
  70. ];
  71. const tasksList = [
  72. "6813de78-f821-4a84-8e8c-3aa89c15b2aa",
  73. "fce2e806-a6c7-4de2-abc2-260d13bcfb2f",
  74. "0bcb7d19-7c63-4933-96b0-00141ce54dbe",
  75. "2f3241c5-29a0-4f47-acf3-9370baf94e74",
  76. "d2b35062-40c1-48b8-bca5-c48779ccc66d",
  77. "ab2fd158-b894-47bc-aadb-645259b46cc0",
  78. "3861cd8e-5393-4285-b6ee-29a5ee301ee5",
  79. "1a75844a-a108-4fbd-bfc3-c7476b26b73d",
  80. "217e2f67-c110-4ef7-a636-8ac0623df3e8",
  81. "49c1db40-8ecf-4454-af0a-fcc81b222135",
  82. "2e6ff98c-132b-4886-8f38-6c89d1a7b02a",
  83. "9fc278e8-4045-4130-9f52-6ce3b713318c",
  84. "4f913da3-58b6-4636-a2c2-912fb01c73d4",
  85. "6216f4e1-eafb-4442-a5d4-5b1830f89655",
  86. "ebbba0a4-96d9-4fa4-85f9-6fb07fbc282a",
  87. "5172f361-d28e-4aa2-a3ba-2adfe5057539",
  88. "f81146e9-9ef9-4979-b0a0-437ea5c3e1bb",
  89. "22301ec3-3a75-4758-a886-ab768312ffe5",
  90. "6debaef3-844e-40f3-be6d-d99a6fd9f2a1",
  91. "932d0c29-22ad-4be5-92b4-fc3a2e13aaed",
  92. "05027b13-88a3-42a4-992a-0ce2a53068d4",
  93. "9e0addfa-51fd-4f3b-a6f2-8dbe301265aa",
  94. "4a42ba64-7822-469c-8899-bc07b5dd5d69",
  95. "516d941e-b006-4744-a190-6c3207750854",
  96. "bf9e7362-5eed-4110-bbe3-1289722a36b3",
  97. "7eed7668-e71a-42ed-98ac-a0ded8bc0296",
  98. "2cac41ba-36dd-4389-91b6-f8ee840083db",
  99. "6f888d49-2b59-4ba9-a7be-199dceff45ab"
  100. ];
  101. console.log("开始执行任务列表");
  102. function checkAllRequestsCompleted() {
  103. if (responses.length === tasks.length + tasksList.length) {
  104. showResultDialog(responses);
  105. }
  106. }
  107. tasks.forEach(task => {
  108. GM_xmlhttpRequest({
  109. method: "POST",
  110. url: task.url,
  111. headers: task.headers,
  112. onload: function (response) {
  113. try {
  114. const responseJson = JSON.parse(response.responseText);
  115. responses.push(responseJson.message);
  116. console.log(responseJson.message);
  117. } catch (error) {
  118. responses.push(`解析响应出错: ${error.message}`);
  119. console.error("解析响应出错:", error);
  120. }
  121. checkAllRequestsCompleted();
  122. },
  123. onerror: function (error) {
  124. console.error("请求失败:", error);
  125. responses.push(`请求失败:${error.status}`);
  126. checkAllRequestsCompleted();
  127. }
  128. });
  129. });
  130. console.log("零碎任务");
  131. tasksList.forEach(taskId => {
  132. const url = "https://hub-api.agnthub.ai/api/tasks/start/" + taskId;
  133. const headers = {
  134. "Accept": "application/json, text/plain, */*",
  135. "Accept-Encoding": "gzip, deflate, br, zstd",
  136. "Accept-Language": "zh-CN,zh;q=0.9",
  137. "Content-Length": "0",
  138. "Cookie": currentCookie,
  139. "Origin": "https://quests.agnthub.ai",
  140. "Priority": "u=1, i",
  141. "Referer": "https://quests.agnthub.ai/",
  142. "Sec-CH-UA": '"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"',
  143. "Sec-CH-UA-Mobile": "?0",
  144. "Sec-CH-UA-Platform": '"Windows"',
  145. "Sec-Fetch-Dest": "empty",
  146. "Sec-Fetch-Mode": "cors",
  147. "Sec-Fetch-Site": "same-site",
  148. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
  149. };
  150. function retryRequest(retryCount) {
  151. if (retryCount > 3) {
  152. responses.push(`请求 ${url} 失败,达到最大重试次数`);
  153. checkAllRequestsCompleted();
  154. return;
  155. }
  156. GM_xmlhttpRequest({
  157. method: "POST",
  158. url: url,
  159. headers: headers,
  160. onload: function (response) {
  161. try {
  162. if (response.status === 201) {
  163. const responseJson = JSON.parse(response.responseText);
  164. responses.push(responseJson.description);
  165. console.log(responseJson.description);
  166. } else {
  167. const responseJson = JSON.parse(response.responseText);
  168. console.log(`请求失败: ${responseJson.message}`);
  169. responses.push(`请求失败,状态码:${response.status}`);
  170. retryRequest(retryCount + 1);
  171. }
  172. } catch (error) {
  173. responses.push(`解析响应出错: ${error.message}`);
  174. console.error("解析响应出错:", error);
  175. retryRequest(retryCount + 1);
  176. }
  177. checkAllRequestsCompleted();
  178. },
  179. onerror: function (error) {
  180. console.error("请求失败:", error);
  181. responses.push(`出现错误:${error.status},重试...`);
  182. retryRequest(retryCount + 1);
  183. }
  184. });
  185. }
  186. retryRequest(1);
  187. });
  188. });
  189. function showResultDialog(responses) {
  190. const dialog = document.createElement("div");
  191. dialog.style.position = "fixed";
  192. dialog.style.top = "50%";
  193. dialog.style.left = "50%";
  194. dialog.style.transform = "translate(-50%, -50%)";
  195. dialog.style.padding = "20px";
  196. dialog.style.backgroundColor = "#f9f9f9";
  197. dialog.style.border = "1px solid #ddd";
  198. dialog.style.borderRadius = "10px";
  199. dialog.style.boxShadow = "0 4px 10px rgba(0, 0, 0, 0.1)";
  200. dialog.style.zIndex = "10001";
  201. dialog.style.width = "800px";
  202. dialog.style.textAlign = "center";
  203. dialog.style.maxHeight = "80vh";
  204. dialog.style.overflowY = "auto";
  205. const title = document.createElement("h3");
  206. title.textContent = "操作完成";
  207. title.style.color = "#333";
  208. title.style.marginBottom = "10px";
  209. dialog.appendChild(title);
  210. const resultText = document.createElement("pre");
  211. resultText.textContent = responses.join("\n\n");
  212. resultText.style.whiteSpace = "pre-wrap";
  213. resultText.style.overflowX = "auto";
  214. resultText.style.maxHeight = "300px";
  215. resultText.style.marginBottom = "15px";
  216. resultText.style.padding = "10px";
  217. resultText.style.border = "1px solid #eee";
  218. resultText.style.borderRadius = "5px";
  219. resultText.style.backgroundColor = "#fff";
  220. resultText.style.width = "100%";
  221. dialog.appendChild(resultText);
  222. const buttonContainer = document.createElement("div");
  223. buttonContainer.style.display = "flex";
  224. buttonContainer.style.justifyContent = "center";
  225. buttonContainer.style.gap = "10px";
  226. buttonContainer.style.marginTop = "15px";
  227. dialog.appendChild(buttonContainer);
  228. const refreshButton = document.createElement("button");
  229. refreshButton.textContent = "刷新";
  230. refreshButton.style.padding = "8px 16px";
  231. refreshButton.style.backgroundColor = "#007bff";
  232. refreshButton.style.color = "#fff";
  233. refreshButton.style.border = "none";
  234. refreshButton.style.borderRadius = "5px";
  235. refreshButton.style.cursor = "pointer";
  236. refreshButton.addEventListener("click", function () {
  237. location.reload();
  238. });
  239. buttonContainer.appendChild(refreshButton);
  240. const cancelButton = document.createElement("button");
  241. cancelButton.textContent = "取消";
  242. cancelButton.style.padding = "8px 16px";
  243. cancelButton.style.backgroundColor = "#ccc";
  244. cancelButton.style.color = "#333";
  245. cancelButton.style.border = "none";
  246. cancelButton.style.borderRadius = "5px";
  247. cancelButton.style.cursor = "pointer";
  248. cancelButton.addEventListener("click", function () {
  249. dialog.remove();
  250. });
  251. buttonContainer.appendChild(cancelButton);
  252. document.body.appendChild(dialog);
  253. }
  254. document.body.appendChild(executeButton);
  255. })();