Web3TestApiMagicNewtonRoll.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // ==UserScript==
  2. // @name 赌狗骰子
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 使用自定义请求头和POST数据发起请求,并携带当前页面的Cookie
  6. // @author Jack
  7. // @match https://www.magicnewton.com/*
  8. // @grant GM_xmlhttpRequest
  9. // @connect www.magicnewton.com
  10. // ==/UserScript==
  11. (function () {
  12. "use strict";
  13. const executeButton = document.createElement("button");
  14. executeButton.textContent = "买定离手 6666 起机";
  15. executeButton.style.position = "fixed";
  16. executeButton.style.top = "20px";
  17. executeButton.style.left = "50%";
  18. executeButton.style.padding = "10px 20px";
  19. executeButton.style.backgroundColor = "#007bff";
  20. executeButton.style.color = "#fff";
  21. executeButton.style.border = "none";
  22. executeButton.style.borderRadius = "5px";
  23. executeButton.style.cursor = "pointer";
  24. executeButton.style.zIndex = "10000";
  25. executeButton.addEventListener("click", function () {
  26. const currentCookie = document.cookie;
  27. const targetUrl = "https://www.magicnewton.com/portal/api/userQuests";
  28. const postData = {
  29. questId: "f56c760b-2186-40cb-9cbc-3af4a3dc20e2",
  30. metadata: { action: "ROLL" }
  31. };
  32. const responses = [];
  33. function makeRequest(retryCount) {
  34. GM_xmlhttpRequest({
  35. method: "POST",
  36. url: targetUrl,
  37. data: JSON.stringify(postData),
  38. headers: {
  39. "Content-Type": "application/json",
  40. "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",
  41. Referer: window.location.href,
  42. Origin: "https://www.magicnewton.com",
  43. "Sec-Fetch-Site": "same-origin",
  44. "Sec-Fetch-Mode": "cors",
  45. "Sec-Fetch-Dest": "empty",
  46. Accept: "*/*",
  47. "Accept-Encoding": "gzip, deflate, br, zstd",
  48. "Accept-Language": "zh-CN,zh;q=0.9",
  49. Cookie: currentCookie
  50. },
  51. onload: function (response) {
  52. try {
  53. const responseJson = JSON.parse(response.responseText);
  54. responses.push(responseJson);
  55. if (responseJson.message === "Quest already completed") {
  56. responses.push("任务已完成,不再继续请求");
  57. showResultDialog(responses);
  58. return;
  59. }
  60. if (retryCount < 5) {
  61. makeRequest(retryCount + 1);
  62. } else {
  63. responses.push("请求完成,已达到最大尝试次数");
  64. showResultDialog(responses);
  65. }
  66. } catch (e) {
  67. responses.push(`解析响应失败:${e.message}`);
  68. showResultDialog(responses);
  69. }
  70. },
  71. onerror: function (error) {
  72. responses.push(`请求失败:${error.status}`);
  73. showResultDialog(responses);
  74. }
  75. });
  76. }
  77. makeRequest(0);
  78. function showResultDialog(responses) {
  79. const dialog = document.createElement("div");
  80. dialog.style.position = "fixed";
  81. dialog.style.top = "50%";
  82. dialog.style.left = "50%";
  83. dialog.style.transform = "translate(-50%, -50%)";
  84. dialog.style.padding = "20px";
  85. dialog.style.backgroundColor = "#f9f9f9";
  86. dialog.style.border = "1px solid #ddd";
  87. dialog.style.borderRadius = "10px";
  88. dialog.style.boxShadow = "0 4px 10px rgba(0, 0, 0, 0.1)";
  89. dialog.style.zIndex = "10001";
  90. dialog.style.width = "800px";
  91. dialog.style.textAlign = "center";
  92. dialog.style.maxHeight = "80vh";
  93. dialog.style.overflowY = "auto";
  94. const title = document.createElement("h3");
  95. title.textContent = "操作完成";
  96. title.style.color = "#333";
  97. title.style.marginBottom = "10px";
  98. dialog.appendChild(title);
  99. const resultText = document.createElement("pre");
  100. resultText.textContent = JSON.stringify(responses, null, 2);
  101. resultText.style.whiteSpace = "pre-wrap";
  102. resultText.style.overflowX = "auto";
  103. resultText.style.maxHeight = "300px";
  104. resultText.style.marginBottom = "15px";
  105. resultText.style.padding = "10px";
  106. resultText.style.border = "1px solid #eee";
  107. resultText.style.borderRadius = "5px";
  108. resultText.style.backgroundColor = "#fff";
  109. resultText.style.width = "100%";
  110. dialog.appendChild(resultText);
  111. const buttonContainer = document.createElement("div");
  112. buttonContainer.style.display = "flex";
  113. buttonContainer.style.justifyContent = "center";
  114. buttonContainer.style.gap = "10px";
  115. buttonContainer.style.marginTop = "15px";
  116. dialog.appendChild(buttonContainer);
  117. const refreshButton = document.createElement("button");
  118. refreshButton.textContent = "刷新";
  119. refreshButton.style.padding = "8px 16px";
  120. refreshButton.style.backgroundColor = "#007bff";
  121. refreshButton.style.color = "#fff";
  122. refreshButton.style.border = "none";
  123. refreshButton.style.borderRadius = "5px";
  124. refreshButton.style.cursor = "pointer";
  125. refreshButton.addEventListener("click", function () {
  126. location.reload();
  127. });
  128. buttonContainer.appendChild(refreshButton);
  129. const cancelButton = document.createElement("button");
  130. cancelButton.textContent = "取消";
  131. cancelButton.style.padding = "8px 16px";
  132. cancelButton.style.backgroundColor = "#ccc";
  133. cancelButton.style.color = "#333";
  134. cancelButton.style.border = "none";
  135. cancelButton.style.borderRadius = "5px";
  136. cancelButton.style.cursor = "pointer";
  137. cancelButton.addEventListener("click", function () {
  138. dialog.remove();
  139. });
  140. buttonContainer.appendChild(cancelButton);
  141. document.body.appendChild(dialog);
  142. }
  143. });
  144. document.body.appendChild(executeButton);
  145. })();