commit
ba76b2dfb1
@ -0,0 +1,4 @@ |
||||
# 忽略 macOS 系统生成的 .DS_Store 文件 |
||||
.DS_Store |
||||
.idea |
||||
.vscode |
||||
@ -0,0 +1,12 @@ |
||||
油猴插件填写例子 |
||||
|
||||
// ==UserScript==
|
||||
// @name 脚本名称 |
||||
// @namespace http://tampermonkey.net/ |
||||
// @version 1.6 |
||||
// @description 脚本简介 |
||||
// @author Jack |
||||
// @match https://目标网站(需要监控网站).com/*/* |
||||
// @require http://服务ip:服务端口/scripts/your_script.js |
||||
// @grant none |
||||
// ==/UserScript==
|
||||
Binary file not shown.
@ -0,0 +1,281 @@ |
||||
// ==UserScript==
|
||||
// @name AGNT.Hub Task Automation
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 0.1
|
||||
// @description Automate AGNT.Hub tasks using current page's Cookie and Headers
|
||||
// @author Jack
|
||||
// @match https://quests.agnthub.ai/*
|
||||
// @grant GM_xmlhttpRequest
|
||||
// @connect hub-api.agnthub.ai
|
||||
// @connect quests.agnthub.ai
|
||||
// ==/UserScript==
|
||||
|
||||
(function () { |
||||
"use strict"; |
||||
|
||||
const executeButton = document.createElement("button"); |
||||
executeButton.textContent = "恶魔城,启动!!"; |
||||
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 responses = []; |
||||
|
||||
const tasks = [ |
||||
{ |
||||
url: "https://hub-api.agnthub.ai/api/daily-rewards/claim", |
||||
headers: { |
||||
accept: "application/json, text/plain, */*", |
||||
"accept-encoding": "gzip, deflate, br, zstd", |
||||
"accept-language": "zh-CN,zh;q=0.9", |
||||
"content-length": "0", |
||||
cookie: currentCookie, |
||||
origin: "https://quests.agnthub.ai", |
||||
priority: "u=1, i", |
||||
referer: "https://quests.agnthub.ai/", |
||||
"sec-ch-ua": |
||||
'"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"', |
||||
"sec-ch-ua-mobile": "?0", |
||||
"sec-ch-ua-platform": '"Windows"', |
||||
"sec-fetch-dest": "empty", |
||||
"sec-fetch-mode": "cors", |
||||
"sec-fetch-site": "same-site", |
||||
"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", |
||||
}, |
||||
}, |
||||
{ |
||||
url: "https://hub-api.agnthub.ai/api/tasks/make-ai-laugh/34ecad1e-94df-48ba-b5f4-242fdd9d6546", |
||||
headers: { |
||||
accept: "application/json, text/plain, */*", |
||||
"accept-encoding": "gzip, deflate, br, zstd", |
||||
"accept-language": "zh-CN,zh;q=0.9", |
||||
"content-length": "0", |
||||
cookie: currentCookie, |
||||
origin: "https://quests.agnthub.ai", |
||||
priority: "u=1, i", |
||||
referer: "https://quests.agnthub.ai/", |
||||
"sec-ch-ua": |
||||
'"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"', |
||||
"sec-ch-ua-mobile": "?0", |
||||
"sec-ch-ua-platform": '"Windows"', |
||||
"sec-fetch-dest": "empty", |
||||
"sec-fetch-mode": "cors", |
||||
"sec-fetch-site": "same-site", |
||||
"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", |
||||
}, |
||||
}, |
||||
]; |
||||
|
||||
const tasksList = [ |
||||
"6813de78-f821-4a84-8e8c-3aa89c15b2aa", |
||||
"fce2e806-a6c7-4de2-abc2-260d13bcfb2f", |
||||
"0bcb7d19-7c63-4933-96b0-00141ce54dbe", |
||||
"2f3241c5-29a0-4f47-acf3-9370baf94e74", |
||||
"d2b35062-40c1-48b8-bca5-c48779ccc66d", |
||||
"ab2fd158-b894-47bc-aadb-645259b46cc0", |
||||
"3861cd8e-5393-4285-b6ee-29a5ee301ee5", |
||||
"1a75844a-a108-4fbd-bfc3-c7476b26b73d", |
||||
"217e2f67-c110-4ef7-a636-8ac0623df3e8", |
||||
"49c1db40-8ecf-4454-af0a-fcc81b222135", |
||||
"2e6ff98c-132b-4886-8f38-6c89d1a7b02a", |
||||
"9fc278e8-4045-4130-9f52-6ce3b713318c", |
||||
"4f913da3-58b6-4636-a2c2-912fb01c73d4", |
||||
"6216f4e1-eafb-4442-a5d4-5b1830f89655", |
||||
"ebbba0a4-96d9-4fa4-85f9-6fb07fbc282a", |
||||
"5172f361-d28e-4aa2-a3ba-2adfe5057539", |
||||
"f81146e9-9ef9-4979-b0a0-437ea5c3e1bb", |
||||
"22301ec3-3a75-4758-a886-ab768312ffe5", |
||||
"6debaef3-844e-40f3-be6d-d99a6fd9f2a1", |
||||
"932d0c29-22ad-4be5-92b4-fc3a2e13aaed", |
||||
"05027b13-88a3-42a4-992a-0ce2a53068d4", |
||||
"9e0addfa-51fd-4f3b-a6f2-8dbe301265aa", |
||||
"4a42ba64-7822-469c-8899-bc07b5dd5d69", |
||||
"516d941e-b006-4744-a190-6c3207750854", |
||||
"bf9e7362-5eed-4110-bbe3-1289722a36b3", |
||||
"7eed7668-e71a-42ed-98ac-a0ded8bc0296", |
||||
"2cac41ba-36dd-4389-91b6-f8ee840083db", |
||||
"6f888d49-2b59-4ba9-a7be-199dceff45ab", |
||||
]; |
||||
console.log("开始执行任务列表"); |
||||
|
||||
function checkAllRequestsCompleted() { |
||||
if (responses.length === tasks.length + tasksList.length) { |
||||
showResultDialog(responses); |
||||
} |
||||
} |
||||
|
||||
tasks.forEach((task) => { |
||||
GM_xmlhttpRequest({ |
||||
method: "POST", |
||||
url: task.url, |
||||
headers: task.headers, |
||||
onload: function (response) { |
||||
try { |
||||
const responseJson = JSON.parse(response.responseText); |
||||
responses.push(responseJson.message); |
||||
console.log(responseJson.message); |
||||
} catch (error) { |
||||
responses.push(`解析响应出错: ${error.message}`); |
||||
console.error("解析响应出错:", error); |
||||
} |
||||
checkAllRequestsCompleted(); |
||||
}, |
||||
onerror: function (error) { |
||||
console.error("请求失败:", error); |
||||
responses.push(`请求失败:${error.status}`); |
||||
checkAllRequestsCompleted(); |
||||
}, |
||||
}); |
||||
}); |
||||
console.log("零碎任务"); |
||||
tasksList.forEach((taskId) => { |
||||
const url = "https://hub-api.agnthub.ai/api/tasks/start/" + taskId; |
||||
const headers = { |
||||
Accept: "application/json, text/plain, */*", |
||||
"Accept-Encoding": "gzip, deflate, br, zstd", |
||||
"Accept-Language": "zh-CN,zh;q=0.9", |
||||
"Content-Length": "0", |
||||
Cookie: currentCookie, |
||||
Origin: "https://quests.agnthub.ai", |
||||
Priority: "u=1, i", |
||||
Referer: "https://quests.agnthub.ai/", |
||||
"Sec-CH-UA": |
||||
'"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"', |
||||
"Sec-CH-UA-Mobile": "?0", |
||||
"Sec-CH-UA-Platform": '"Windows"', |
||||
"Sec-Fetch-Dest": "empty", |
||||
"Sec-Fetch-Mode": "cors", |
||||
"Sec-Fetch-Site": "same-site", |
||||
"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", |
||||
}; |
||||
|
||||
function retryRequest(retryCount) { |
||||
if (retryCount > 3) { |
||||
responses.push(`请求 ${url} 失败,达到最大重试次数`); |
||||
checkAllRequestsCompleted(); |
||||
return; |
||||
} |
||||
|
||||
GM_xmlhttpRequest({ |
||||
method: "POST", |
||||
url: url, |
||||
headers: headers, |
||||
onload: function (response) { |
||||
try { |
||||
if (response.status === 201) { |
||||
const responseJson = JSON.parse(response.responseText); |
||||
responses.push(responseJson.description); |
||||
console.log(responseJson.description); |
||||
} else { |
||||
const responseJson = JSON.parse(response.responseText); |
||||
console.log(`请求失败: ${responseJson.message}`); |
||||
responses.push(`请求失败,状态码:${response.status}`); |
||||
retryRequest(retryCount + 1); |
||||
} |
||||
} catch (error) { |
||||
responses.push(`解析响应出错: ${error.message}`); |
||||
console.error("解析响应出错:", error); |
||||
retryRequest(retryCount + 1); |
||||
} |
||||
checkAllRequestsCompleted(); |
||||
}, |
||||
onerror: function (error) { |
||||
console.error("请求失败:", error); |
||||
responses.push(`出现错误:${error.status},重试...`); |
||||
retryRequest(retryCount + 1); |
||||
}, |
||||
}); |
||||
} |
||||
|
||||
retryRequest(1); |
||||
}); |
||||
}); |
||||
|
||||
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 = responses.join("\n\n"); |
||||
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); |
||||
})(); |
||||
@ -0,0 +1,105 @@ |
||||
// ==UserScript==
|
||||
// @name Sepolia Faucet Monitor and Button Clicker
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 0.6
|
||||
// @description Monitor the value of a specific element, and click buttons in a loop when the value is greater than or equal to 2
|
||||
// @author Jack
|
||||
// @match https://sepolia-faucet.pk910.de/*
|
||||
// @grant none
|
||||
// ==/UserScript==
|
||||
|
||||
(function() { |
||||
'use strict'; |
||||
|
||||
// 目标元素的CSS选择器
|
||||
const valueElementSelector = 'body > div.faucet-wrapper > div > div > div > div.faucet-body > div > div.pow-status-container > div > div.row.pow-status-top > div:nth-child(1) > div.status-value'; |
||||
const firstButtonSelector = 'body > div.faucet-wrapper > div > div > div > div.faucet-body > div > div.faucet-actions.center > button'; |
||||
const secondButtonSelector = 'body > div.faucet-wrapper > div > div > div > div.faucet-body > div > div > div:nth-child(2) > div:nth-child(4) > div > div > button'; |
||||
const maxFaucetValue = 2.49; |
||||
|
||||
// 发送消息到 Gotify
|
||||
function sendMessageToGotify(title = "按钮点击通知", message = "第二个按钮已点击") { |
||||
const gotifyUrl = "https://gotify.erhe.top/message?token=A9KF--mx_12PjSu"; |
||||
const payload = { |
||||
message: message, |
||||
title: title, |
||||
priority: 5 |
||||
}; |
||||
|
||||
fetch(gotifyUrl, { |
||||
method: 'POST', |
||||
headers: { |
||||
'Content-Type': 'application/json' |
||||
}, |
||||
body: JSON.stringify(payload) |
||||
}) |
||||
.then(response => { |
||||
if (response.ok) { |
||||
console.log("消息发送成功"); |
||||
} else { |
||||
console.error(`消息发送失败,状态码: ${response.status}`); |
||||
} |
||||
}) |
||||
.catch(error => { |
||||
console.error(`请求出现异常: ${error}`); |
||||
}); |
||||
} |
||||
|
||||
// 监控函数
|
||||
function monitorElement() { |
||||
// 获取目标元素
|
||||
const valueElement = document.querySelector(valueElementSelector); |
||||
|
||||
// 如果元素存在,则提取浮点数部分
|
||||
if (valueElement) { |
||||
const valueText = valueElement.textContent; |
||||
const floatValue = parseFloat(valueText); |
||||
|
||||
// 如果浮点数大于等于 2,则进入死循环点击按钮
|
||||
if (!isNaN(floatValue) && floatValue >= maxFaucetValue) { |
||||
console.log(`Value is ${floatValue}, entering loop to click buttons...`); |
||||
clickButtonsLoop(); |
||||
} else { |
||||
console.log(`Value is ${floatValue}`); |
||||
} |
||||
} else { |
||||
console.log('Target value element not found.'); |
||||
} |
||||
} |
||||
|
||||
// 点击按钮循环函数
|
||||
function clickButtonsLoop() { |
||||
// 点击第一个按钮
|
||||
const firstButton = document.querySelector(firstButtonSelector); |
||||
if (firstButton) { |
||||
firstButton.click(); |
||||
} |
||||
|
||||
// 点击第二个按钮
|
||||
const secondButton = document.querySelector(secondButtonSelector); |
||||
if (secondButton) { |
||||
secondButton.click(); |
||||
// 第二个按钮点击后发送消息
|
||||
sendMessageToGotify(); |
||||
} |
||||
|
||||
// 继续循环
|
||||
setTimeout(clickButtonsLoop, 1000); |
||||
} |
||||
|
||||
// 隐藏图片函数
|
||||
function hideImage() { |
||||
// 使用 XPath 查找元素
|
||||
const imageElement = document.evaluate('/html/body/div[2]/div/div/div/div[3]/div/div[1]/div/div[1]/div/img', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; |
||||
if (imageElement) { |
||||
imageElement.style.display = 'none'; |
||||
} else { |
||||
console.log('Target image element not found.'); |
||||
} |
||||
} |
||||
|
||||
setTimeout(hideImage, 2000); |
||||
|
||||
// 设置一个死循环,每隔一秒执行一次监控函数
|
||||
setInterval(monitorElement, 1000); |
||||
})(); |
||||
@ -0,0 +1,156 @@ |
||||
// ==UserScript==
|
||||
// @name 创建按钮,发起带请求头和POST数据的请求
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 0.1
|
||||
// @description 使用自定义请求头和POST数据发起请求,并携带当前页面的Cookie
|
||||
// @author Jack
|
||||
// @match *://*/*
|
||||
// @grant GM_xmlhttpRequest
|
||||
// @connect example.com
|
||||
// ==/UserScript==
|
||||
|
||||
(function () { |
||||
"use strict"; |
||||
|
||||
// 创建一个按钮
|
||||
const executeButton = document.createElement("button"); |
||||
executeButton.textContent = "执行"; |
||||
executeButton.style.position = "fixed"; |
||||
executeButton.style.top = "20px"; |
||||
executeButton.style.left = "50%"; |
||||
executeButton.style.padding = "10px 20px"; |
||||
executeButton.style.backgroundColor = "#007bff"; |
||||
executeButton.style.color = "#fff"; |
||||
executeButton.style.border = "none"; |
||||
executeButton.style.borderRadius = "5px"; |
||||
executeButton.style.cursor = "pointer"; |
||||
executeButton.style.zIndex = "10000"; |
||||
|
||||
// 添加点击事件
|
||||
executeButton.addEventListener("click", function () { |
||||
// 获取当前页面的Cookie
|
||||
const currentCookie = document.cookie; |
||||
console.log(currentCookie); |
||||
|
||||
// 请求的目标URL
|
||||
const targetUrl = "https://example.com/api"; // 替换为目标API地址
|
||||
|
||||
// POST请求的数据
|
||||
const postData = { |
||||
key1: "value1", |
||||
key2: "value2", |
||||
}; |
||||
|
||||
// 存储请求结果的数组
|
||||
const responses = []; |
||||
|
||||
for (let i = 0; i < 1; i++) { |
||||
GM_xmlhttpRequest({ |
||||
method: "POST", // 请求方法
|
||||
url: targetUrl, // 请求URL
|
||||
data: JSON.stringify(postData), // POST请求的数据
|
||||
headers: { |
||||
"Content-Type": "application/json", // 设置请求头
|
||||
"User-Agent": "Tampermonkey Script", // 自定义User-Agent
|
||||
Referer: window.location.href, // 当前页面的Referer
|
||||
}, |
||||
cookie: currentCookie, // 使用当前页面的Cookie
|
||||
onload: function (response) { |
||||
responses.push(response.responseText); // 将响应内容添加到数组
|
||||
if (responses.length === 1) { |
||||
showResultDialog(responses); // 显示结果提示框
|
||||
} |
||||
}, |
||||
onerror: function (error) { |
||||
console.error("请求失败:", error); |
||||
responses.push(`请求失败:${error.status}`); // 将错误信息添加到数组
|
||||
if (responses.length === 1) { |
||||
showResultDialog(responses); // 显示结果提示框
|
||||
} |
||||
}, |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
// 显示结果提示框
|
||||
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"; // 最大高度不超过视口的 80%
|
||||
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 = responses.join("\n\n"); // 每次请求结果之间增加换行
|
||||
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); |
||||
})(); |
||||
@ -0,0 +1,34 @@ |
||||
// ==UserScript==
|
||||
// @name 银河任务完成自动跳过
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 1.0
|
||||
// @description 自动跳过银河任务完成弹出的页面
|
||||
// @author Jack
|
||||
// @match https://app.galxe.com/*
|
||||
// @grant none
|
||||
// ==/UserScript==
|
||||
|
||||
(function() { |
||||
'use strict'; |
||||
|
||||
// 定义CSS选择器
|
||||
const selector = '#radix-:r35: > button > span.[&_svg]:text-inherit.[&_svg_path]:fill-current.[&_svg]:h-[1em].h-[1em].[&_svg]:w-[1em].w-[1em].text-base.cursor-pointer.text-common-white.sm:block.sm:text-size-24.block > svg'; |
||||
|
||||
// 监测页面元素
|
||||
const observer = new MutationObserver(mutations => { |
||||
mutations.forEach(mutation => { |
||||
Array.from(mutation.addedNodes).forEach(node => { |
||||
if(node.matches && node.matches(selector)) { |
||||
// 点击按钮
|
||||
node.click(); |
||||
} |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
// 配置observer,观察子节点的变动
|
||||
observer.observe(document.body, { |
||||
childList: true, |
||||
subtree: true |
||||
}); |
||||
})(); |
||||
@ -0,0 +1,31 @@ |
||||
// ==UserScript==
|
||||
// @name Hide Specific Buttons
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 0.1
|
||||
// @description Hide specific buttons on a webpage
|
||||
// @author Jack
|
||||
// @match http://home.erhe.link:18088/*
|
||||
// @grant none
|
||||
// ==/UserScript==
|
||||
|
||||
(function() { |
||||
'use strict'; |
||||
|
||||
// 等待页面加载完成
|
||||
window.addEventListener('load', function() { |
||||
// 定义要隐藏的元素选择器
|
||||
var selectors = [ |
||||
'#root > div > div:nth-child(2)', |
||||
'#root > div > div:nth-child(3)', |
||||
'#root > div > div:nth-child(4)' |
||||
]; |
||||
|
||||
// 遍历选择器并隐藏对应的元素
|
||||
selectors.forEach(function(selector) { |
||||
var element = document.querySelector(selector); |
||||
if (element) { |
||||
element.style.display = 'none'; // 隐藏元素
|
||||
} |
||||
}); |
||||
}); |
||||
})(); |
||||
@ -0,0 +1,115 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"log" |
||||
"net" |
||||
"net/http" |
||||
"os" |
||||
"path/filepath" |
||||
) |
||||
|
||||
const scriptsDir = "scripts" |
||||
|
||||
func getLocalIP() (string, error) { |
||||
addrs, err := net.InterfaceAddrs() |
||||
if err != nil { |
||||
return "", err |
||||
} |
||||
|
||||
for _, addr := range addrs { |
||||
var ip net.IP |
||||
switch v := addr.(type) { |
||||
case *net.IPNet: |
||||
ip = v.IP |
||||
case *net.IPAddr: |
||||
ip = v.IP |
||||
} |
||||
|
||||
if ip == nil || ip.IsLoopback() { |
||||
continue |
||||
} |
||||
|
||||
ip = ip.To4() |
||||
if ip == nil { |
||||
continue |
||||
} |
||||
|
||||
return ip.String(), nil |
||||
} |
||||
|
||||
return "", fmt.Errorf("no local IP address found") |
||||
} |
||||
|
||||
func main() { |
||||
// 服务端口号
|
||||
port := "18123" |
||||
|
||||
// 确保脚本目录存在
|
||||
if _, err := os.Stat(scriptsDir); os.IsNotExist(err) { |
||||
os.Mkdir(scriptsDir, os.ModePerm) |
||||
} |
||||
|
||||
// 遍历脚本目录并输出文件列表
|
||||
files, err := os.ReadDir(scriptsDir) |
||||
if err != nil { |
||||
log.Fatalf("无法读取脚本目录: %v", err) |
||||
} |
||||
|
||||
if len(files) > 0 { |
||||
ip, err := getLocalIP() |
||||
if err != nil { |
||||
fmt.Println("Error:", err) |
||||
} else { |
||||
fmt.Println("Local IP address:", ip) |
||||
} |
||||
|
||||
fmt.Println("脚本目录下的文件有:") |
||||
for _, file := range files { |
||||
if !file.IsDir() { |
||||
fmt.Printf("// @require http://%s:%s/scripts/%s\n", ip, port, file.Name()) |
||||
} |
||||
} |
||||
} else { |
||||
fmt.Println("脚本目录为空。") |
||||
} |
||||
fmt.Println("") |
||||
|
||||
// 提供脚本下载
|
||||
http.HandleFunc("/scripts/", func(w http.ResponseWriter, r *http.Request) { |
||||
if r.Method == http.MethodGet { |
||||
fileName := filepath.Base(r.URL.Path) |
||||
filePath := filepath.Join(scriptsDir, fileName) |
||||
|
||||
// 检查文件是否存在
|
||||
if _, err := os.Stat(filePath); os.IsNotExist(err) { |
||||
http.Error(w, "脚本未找到", http.StatusNotFound) |
||||
return |
||||
} |
||||
|
||||
// 打开文件
|
||||
file, err := os.Open(filePath) |
||||
if err != nil { |
||||
http.Error(w, "无法打开文件", http.StatusInternalServerError) |
||||
return |
||||
} |
||||
defer file.Close() |
||||
|
||||
// 获取文件的修改时间
|
||||
fileInfo, err := file.Stat() |
||||
if err != nil { |
||||
http.Error(w, "无法获取文件信息", http.StatusInternalServerError) |
||||
return |
||||
} |
||||
|
||||
// 提供文件下载
|
||||
http.ServeContent(w, r, fileName, fileInfo.ModTime(), file) |
||||
} else { |
||||
http.Error(w, "不支持的方法", http.StatusMethodNotAllowed) |
||||
} |
||||
}) |
||||
|
||||
// 启动服务器
|
||||
fmt.Printf("服务器已启动,监听端口: %s\n", port) |
||||
log.Fatal(http.ListenAndServe(":"+port, nil)) |
||||
} |
||||
@ -0,0 +1,162 @@ |
||||
// ==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); |
||||
})(); |
||||
@ -0,0 +1,36 @@ |
||||
// ==UserScript==
|
||||
// @name 获取并复制Cookie
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 1.0
|
||||
// @description 点击复制当前页面Cookie
|
||||
// @author Jack
|
||||
// @match *://*/*
|
||||
// @grant GM_setClipboard
|
||||
// ==/UserScript==
|
||||
|
||||
(function() { |
||||
'use strict'; |
||||
|
||||
const button = document.createElement("button"); |
||||
button.textContent = "Copy Cookie"; |
||||
button.style.position = "fixed"; |
||||
button.style.top = "10%"; |
||||
button.style.right = "1%"; |
||||
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"; |
||||
|
||||
document.body.appendChild(button); |
||||
|
||||
button.addEventListener('click', () => { |
||||
const cookies = document.cookie; |
||||
GM_setClipboard(cookies, { type: 'text' }); |
||||
alert(`Cookie已复制到剪贴板!\n\n${cookies}`); |
||||
}); |
||||
})(); |
||||
@ -0,0 +1,44 @@ |
||||
// ==UserScript==
|
||||
// @name Disable Pop-ups Button
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 1.0
|
||||
// @description 在任意页面添加按钮,点击后禁用 window.open 弹窗行为
|
||||
// @author Jack
|
||||
// @match *://*/*
|
||||
// @grant none
|
||||
// ==/UserScript==
|
||||
|
||||
(function() { |
||||
'use strict'; |
||||
|
||||
// 创建按钮
|
||||
const button = document.createElement('button'); |
||||
button.textContent = "Disable Pop-ups"; |
||||
|
||||
// 按钮样式
|
||||
button.style.position = "fixed"; |
||||
button.style.top = "12.5%"; |
||||
button.style.right = "1%"; |
||||
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"; |
||||
|
||||
// 点击事件,覆盖 window.open
|
||||
button.addEventListener('click', () => { |
||||
const originalOpen = window.open; |
||||
window.open = function() { |
||||
return originalOpen('', '_self'); |
||||
}; |
||||
// 可选:点击后提示用户已禁用弹窗
|
||||
alert('Pop-ups have been disabled for this page.'); |
||||
}); |
||||
|
||||
// 挂载按钮到页面
|
||||
document.body.appendChild(button); |
||||
})(); |
||||
@ -0,0 +1,42 @@ |
||||
// ==UserScript==
|
||||
// @name Remove All Images
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 0.1
|
||||
// @description Add a button to remove all images on the page
|
||||
// @author You
|
||||
// @match *://*/*
|
||||
// @grant none
|
||||
// ==/UserScript==
|
||||
|
||||
(function() { |
||||
'use strict'; |
||||
|
||||
// 创建按钮元素
|
||||
const button = document.createElement('button'); |
||||
button.textContent = "Remove Img"; |
||||
button.style.position = "fixed"; |
||||
button.style.top = "12.5%"; |
||||
button.style.right = "1%"; |
||||
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"; |
||||
|
||||
// 为按钮添加点击事件监听器
|
||||
button.addEventListener('click', function() { |
||||
// 获取页面上的所有图片元素
|
||||
const images = document.querySelectorAll('img'); |
||||
// 遍历所有图片元素并移除它们
|
||||
images.forEach(image => { |
||||
image.parentNode.removeChild(image); |
||||
}); |
||||
}); |
||||
|
||||
// 将按钮添加到页面的 body 元素中
|
||||
document.body.appendChild(button); |
||||
})(); |
||||
@ -0,0 +1,85 @@ |
||||
// ==UserScript==
|
||||
// @name sosovalue 半自动点击
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 1.6
|
||||
// @description 检测并点击页面中的 5 组按钮,并关闭新弹出的页面
|
||||
// @author Jack
|
||||
// @match https://sosovalue.com/*/*
|
||||
// @grant none
|
||||
// ==/UserScript==
|
||||
|
||||
(function () { |
||||
"use strict"; |
||||
|
||||
const GroupSelectors = [ |
||||
"#\\:rf\\: > span.transition-opacity.font-medium", |
||||
"#\\:rh\\: > span.transition-opacity.font-medium", |
||||
"#\\:ri\\: > span.transition-opacity.font-medium", |
||||
"#\\:rj\\: > span.transition-opacity.font-medium", |
||||
"#\\:rk\\: > span.transition-opacity.font-medium", |
||||
"#\\:rg\\: > span.transition-opacity.font-medium", |
||||
]; |
||||
|
||||
let newWindow = null; |
||||
|
||||
const originalOpen = window.open; |
||||
window.open = function (url, name, features) { |
||||
newWindow = originalOpen(url, name, features); |
||||
return newWindow; |
||||
}; |
||||
|
||||
function clickButtonGroup(group, delay, closeWindow = false, callback) { |
||||
let completed = 0; |
||||
group.forEach((selector, index) => { |
||||
setTimeout(() => { |
||||
const button = document.querySelector(selector); |
||||
if (button) { |
||||
button.click(); |
||||
if (closeWindow && newWindow) { |
||||
newWindow.close(); |
||||
} |
||||
} |
||||
completed++; |
||||
if (completed === group.length && callback) { |
||||
callback(); |
||||
} |
||||
}, index * delay); |
||||
}); |
||||
} |
||||
|
||||
function createCustomButtons() { |
||||
const button = document.createElement("button"); |
||||
button.textContent = "执行"; |
||||
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"; |
||||
|
||||
button.addEventListener("click", () => { |
||||
clickButtonGroup(GroupSelectors, 1000, true, () => { |
||||
// 所有按钮点击完成后,等待1秒刷新页面
|
||||
setTimeout(() => { |
||||
location.reload(); |
||||
}, 1000); |
||||
}); |
||||
}); |
||||
|
||||
document.body.appendChild(button); |
||||
} |
||||
|
||||
window.addEventListener("load", createCustomButtons); |
||||
|
||||
setInterval(() => { |
||||
if (newWindow && !newWindow.closed) { |
||||
newWindow.close(); |
||||
} |
||||
}, 1000); |
||||
})(); |
||||
@ -0,0 +1,253 @@ |
||||
// ==UserScript==
|
||||
// @name Web3网络快速切换器
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 1.1
|
||||
// @description 在页面上添加下拉框快速切换Web3钱包网络
|
||||
// @author You
|
||||
// @match *://*/*
|
||||
// @grant GM_notification
|
||||
// ==/UserScript==
|
||||
|
||||
(function() { |
||||
'use strict'; |
||||
|
||||
// 配置:预设的网络列表(目前只有Monad测试网,您可以自行添加)
|
||||
const networks = [ |
||||
{ name: "Monad Testnet", chainId: "0x4a", rpcUrls: ["https://testnet.monad.xyz"] } |
||||
// 您可以在这里添加其他网络,格式如下:
|
||||
// { name: "网络名称", chainId: "网络ID", rpcUrls: ["RPC URL"] },
|
||||
]; |
||||
|
||||
// 创建样式
|
||||
const style = document.createElement('style'); |
||||
style.textContent = ` |
||||
.web3-network-switcher { |
||||
position: fixed; |
||||
top: 20px; |
||||
right: 20px; |
||||
z-index: 9999; |
||||
padding: 10px; |
||||
background-color: rgba(255, 255, 255, 0.95); |
||||
border: 1px solid #ccc; |
||||
border-radius: 8px; |
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); |
||||
font-family: Arial, sans-serif; |
||||
min-width: 200px; |
||||
} |
||||
.web3-network-switcher label { |
||||
display: block; |
||||
margin-bottom: 8px; |
||||
font-weight: bold; |
||||
color: #333; |
||||
} |
||||
.web3-network-switcher select { |
||||
width: 100%; |
||||
padding: 8px; |
||||
border-radius: 4px; |
||||
border: 1px solid #ddd; |
||||
background-color: white; |
||||
font-size: 14px; |
||||
} |
||||
.web3-network-switcher select:focus { |
||||
outline: none; |
||||
border-color: #4a90e2; |
||||
box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2); |
||||
} |
||||
.web3-network-switcher .status { |
||||
margin-top: 8px; |
||||
font-size: 12px; |
||||
color: #666; |
||||
} |
||||
.web3-network-switcher .toggle { |
||||
position: absolute; |
||||
top: 5px; |
||||
right: 5px; |
||||
cursor: pointer; |
||||
font-weight: bold; |
||||
color: #999; |
||||
} |
||||
.web3-network-switcher.collapsed { |
||||
width: auto; |
||||
min-width: auto; |
||||
padding: 5px; |
||||
} |
||||
.web3-network-switcher.collapsed select, |
||||
.web3-network-switcher.collapsed label, |
||||
.web3-network-switcher.collapsed .status { |
||||
display: none; |
||||
} |
||||
`;
|
||||
document.head.appendChild(style); |
||||
|
||||
// 等待页面加载完成后执行
|
||||
setTimeout(init, 2000); |
||||
|
||||
function init() { |
||||
// 如果页面已存在切换器,先移除
|
||||
const existing = document.getElementById('web3-network-switcher'); |
||||
if (existing) existing.remove(); |
||||
|
||||
// 重新初始化
|
||||
if (typeof window.ethereum !== 'undefined') { |
||||
// 这里需要执行createNetworkSelector函数
|
||||
// 可能需要将函数改为全局可访问
|
||||
console.log('Web3钱包已检测到'); |
||||
} else { |
||||
console.log('未检测到Web3钱包'); |
||||
} |
||||
|
||||
// 创建网络选择器
|
||||
createNetworkSelector(); |
||||
} |
||||
|
||||
function createNetworkSelector() { |
||||
// 如果已存在,先移除
|
||||
const existing = document.getElementById('web3-network-switcher'); |
||||
if (existing) existing.remove(); |
||||
|
||||
// 创建容器
|
||||
const container = document.createElement('div'); |
||||
container.className = 'web3-network-switcher'; |
||||
container.id = 'web3-network-switcher'; |
||||
|
||||
// 创建折叠按钮
|
||||
const toggleBtn = document.createElement('div'); |
||||
toggleBtn.className = 'toggle'; |
||||
toggleBtn.textContent = '−'; |
||||
toggleBtn.title = '折叠/展开'; |
||||
toggleBtn.onclick = function() { |
||||
container.classList.toggle('collapsed'); |
||||
toggleBtn.textContent = container.classList.contains('collapsed') ? '+' : '−'; |
||||
}; |
||||
|
||||
// 创建标签
|
||||
const label = document.createElement('label'); |
||||
label.textContent = '切换到Monad:'; |
||||
label.htmlFor = 'web3-network-select'; |
||||
|
||||
// 创建下拉选择框
|
||||
const select = document.createElement('select'); |
||||
select.id = 'web3-network-select'; |
||||
|
||||
// 添加网络选项
|
||||
networks.forEach(network => { |
||||
const option = document.createElement('option'); |
||||
option.value = network.chainId; |
||||
option.textContent = network.name; |
||||
select.appendChild(option); |
||||
}); |
||||
|
||||
// 添加状态显示
|
||||
const status = document.createElement('div'); |
||||
status.className = 'status'; |
||||
status.textContent = '就绪'; |
||||
status.id = 'web3-network-status'; |
||||
|
||||
// 添加事件监听器
|
||||
select.addEventListener('change', function() { |
||||
const selectedChainId = this.value; |
||||
const selectedNetwork = networks.find(net => net.chainId === selectedChainId); |
||||
|
||||
if (selectedNetwork) { |
||||
status.textContent = `切换中: ${selectedNetwork.name}...`; |
||||
status.style.color = '#4a90e2'; |
||||
switchNetwork(selectedNetwork); |
||||
} |
||||
}); |
||||
|
||||
// 添加到容器
|
||||
container.appendChild(toggleBtn); |
||||
container.appendChild(label); |
||||
container.appendChild(select); |
||||
container.appendChild(status); |
||||
|
||||
// 添加到页面
|
||||
document.body.appendChild(container); |
||||
|
||||
// 添加拖动功能
|
||||
makeDraggable(container); |
||||
} |
||||
|
||||
async function switchNetwork(network) { |
||||
const status = document.getElementById('web3-network-status'); |
||||
|
||||
try { |
||||
// 尝试切换到指定网络
|
||||
await window.ethereum.request({ |
||||
method: 'wallet_switchEthereumChain', |
||||
params: [{ chainId: network.chainId }], |
||||
}); |
||||
|
||||
status.textContent = `已切换到 ${network.name}`; |
||||
status.style.color = 'green'; |
||||
|
||||
} catch (switchError) { |
||||
// 如果网络未添加,尝试添加它
|
||||
if (switchError.code === 4902) { |
||||
status.textContent = '添加新网络中...'; |
||||
status.style.color = '#4a90e2'; |
||||
|
||||
try { |
||||
await window.ethereum.request({ |
||||
method: 'wallet_addEthereumChain', |
||||
params: [{ |
||||
chainId: network.chainId, |
||||
chainName: network.name, |
||||
rpcUrls: network.rpcUrls, |
||||
nativeCurrency: { |
||||
name: 'MON', |
||||
symbol: 'MON', |
||||
decimals: 18 |
||||
}, |
||||
blockExplorerUrls: ['https://explorer.monad.xyz'] |
||||
}], |
||||
}); |
||||
|
||||
status.textContent = `已添加并切换到 ${network.name}`; |
||||
status.style.color = 'green'; |
||||
|
||||
} catch (addError) { |
||||
status.textContent = `添加失败: ${addError.message}`; |
||||
status.style.color = 'red'; |
||||
} |
||||
} else { |
||||
status.textContent = `切换失败: ${switchError.message}`; |
||||
status.style.color = 'red'; |
||||
} |
||||
} |
||||
} |
||||
|
||||
function makeDraggable(element) { |
||||
let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0; |
||||
|
||||
element.onmousedown = dragMouseDown; |
||||
|
||||
function dragMouseDown(e) { |
||||
if (e.target.tagName === 'SELECT' || e.target.tagName === 'OPTION') return; |
||||
|
||||
e = e || window.event; |
||||
e.preventDefault(); |
||||
pos3 = e.clientX; |
||||
pos4 = e.clientY; |
||||
document.onmouseup = closeDragElement; |
||||
document.onmousemove = elementDrag; |
||||
} |
||||
|
||||
function elementDrag(e) { |
||||
e = e || window.event; |
||||
e.preventDefault(); |
||||
pos1 = pos3 - e.clientX; |
||||
pos2 = pos4 - e.clientY; |
||||
pos3 = e.clientX; |
||||
pos4 = e.clientY; |
||||
element.style.top = (element.offsetTop - pos2) + "px"; |
||||
element.style.right = "unset"; |
||||
element.style.left = (element.offsetLeft - pos1) + "px"; |
||||
} |
||||
|
||||
function closeDragElement() { |
||||
document.onmouseup = null; |
||||
document.onmousemove = null; |
||||
} |
||||
} |
||||
})(); |
||||
Loading…
Reference in new issue