Web3TestApiMagicNewtonRoll.js 6.0 KB

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