| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- // ==UserScript==
- // @name 赌狗骰子
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description 使用自定义请求头和POST数据发起请求,并携带当前页面的Cookie
- // @author Jack
- // @match https://www.magicnewton.com/*
- // @grant GM_xmlhttpRequest
- // @connect www.magicnewton.com
- // ==/UserScript==
- (function () {
- "use strict";
-
- const executeButton = document.createElement("button");
- executeButton.textContent = "买定离手 6666 起机";
- button.style.position = "fixed";
- button.style.top = "10%";
- button.style.left = "2%";
- button.style.transform = "translateY(-50%)";
- button.style.padding = "3px 8px";
- button.style.fontSize = "10px";
- button.style.backgroundColor = "#007baf";
- button.style.color = "#fff";
- button.style.border = "none";
- button.style.borderRadius = "5px";
- button.style.cursor = "pointer";
- button.style.zIndex = "10000";
-
- executeButton.addEventListener("click", function () {
- const currentCookie = document.cookie;
- const targetUrl = "https://www.magicnewton.com/portal/api/userQuests";
- const postData = {
- questId: "f56c760b-2186-40cb-9cbc-3af4a3dc20e2",
- metadata: { action: "ROLL" }
- };
- const responses = [];
-
- function makeRequest(retryCount) {
- GM_xmlhttpRequest({
- method: "POST",
- url: targetUrl,
- data: JSON.stringify(postData),
- headers: {
- "Content-Type": "application/json",
- "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",
- Referer: window.location.href,
- Origin: "https://www.magicnewton.com",
- "Sec-Fetch-Site": "same-origin",
- "Sec-Fetch-Mode": "cors",
- "Sec-Fetch-Dest": "empty",
- Accept: "*/*",
- "Accept-Encoding": "gzip, deflate, br, zstd",
- "Accept-Language": "zh-CN,zh;q=0.9",
- Cookie: currentCookie
- },
- onload: function (response) {
- try {
- const responseJson = JSON.parse(response.responseText);
- responses.push(responseJson);
-
- if (responseJson.message === "Quest already completed") {
- responses.push("任务已完成,不再继续请求");
- showResultDialog(responses);
- return;
- }
-
- if (retryCount < 5) {
- makeRequest(retryCount + 1);
- } else {
- responses.push("请求完成,已达到最大尝试次数");
- showResultDialog(responses);
- }
- } catch (e) {
- responses.push(`解析响应失败:${e.message}`);
- showResultDialog(responses);
- }
- },
- onerror: function (error) {
- responses.push(`请求失败:${error.status}`);
- showResultDialog(responses);
- }
- });
- }
-
- makeRequest(0);
-
- function showResultDialog(responses) {
- const dialog = document.createElement("div");
- dialog.style.position = "fixed";
- dialog.style.top = "50%";
- dialog.style.left = "50%";
- dialog.style.transform = "translate(-50%, -50%)";
- dialog.style.padding = "20px";
- dialog.style.backgroundColor = "#f9f9f9";
- dialog.style.border = "1px solid #ddd";
- dialog.style.borderRadius = "10px";
- dialog.style.boxShadow = "0 4px 10px rgba(0, 0, 0, 0.1)";
- dialog.style.zIndex = "10001";
- dialog.style.width = "800px";
- dialog.style.textAlign = "center";
- dialog.style.maxHeight = "80vh";
- dialog.style.overflowY = "auto";
-
- const title = document.createElement("h3");
- title.textContent = "操作完成";
- title.style.color = "#333";
- title.style.marginBottom = "10px";
- dialog.appendChild(title);
-
- const resultText = document.createElement("pre");
- resultText.textContent = JSON.stringify(responses, null, 2);
- resultText.style.whiteSpace = "pre-wrap";
- resultText.style.overflowX = "auto";
- resultText.style.maxHeight = "300px";
- resultText.style.marginBottom = "15px";
- resultText.style.padding = "10px";
- resultText.style.border = "1px solid #eee";
- resultText.style.borderRadius = "5px";
- resultText.style.backgroundColor = "#fff";
- resultText.style.width = "100%";
- dialog.appendChild(resultText);
-
- const buttonContainer = document.createElement("div");
- buttonContainer.style.display = "flex";
- buttonContainer.style.justifyContent = "center";
- buttonContainer.style.gap = "10px";
- buttonContainer.style.marginTop = "15px";
- dialog.appendChild(buttonContainer);
-
- const refreshButton = document.createElement("button");
- refreshButton.textContent = "刷新";
- refreshButton.style.padding = "8px 16px";
- refreshButton.style.backgroundColor = "#007bff";
- refreshButton.style.color = "#fff";
- refreshButton.style.border = "none";
- refreshButton.style.borderRadius = "5px";
- refreshButton.style.cursor = "pointer";
- refreshButton.addEventListener("click", function () {
- location.reload();
- });
- buttonContainer.appendChild(refreshButton);
-
- const cancelButton = document.createElement("button");
- cancelButton.textContent = "取消";
- cancelButton.style.padding = "8px 16px";
- cancelButton.style.backgroundColor = "#ccc";
- cancelButton.style.color = "#333";
- cancelButton.style.border = "none";
- cancelButton.style.borderRadius = "5px";
- cancelButton.style.cursor = "pointer";
- cancelButton.addEventListener("click", function () {
- dialog.remove();
- });
- buttonContainer.appendChild(cancelButton);
-
- document.body.appendChild(dialog);
- }
- });
-
- document.body.appendChild(executeButton);
- })();
|