Web3TestApiAgnt.js 10 KB

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