Jack 1 month ago
parent 09667b2c11
commit 99d3f1d50e
  1. 119
      scripts/agnthub_tasks.js

@ -0,0 +1,119 @@
// ==UserScript==
// @name Eliminate button
// @namespace http://tampermonkey.net/
// @version 0.2
// @description 创建一个按钮,点击后循环点击指定的十个元素
// @author Jack
// @match *://*/*
// @grant none
// ==/UserScript==
'use strict';
// 用于控制循环的变量
let isRunning = false;
let intervalId = null;
// 创建按钮
const button = document.createElement('button');
button.textContent = "甩狙";
// 按钮样式
button.style.position = "fixed";
button.style.top = "50%";
button.style.right = "30%";
button.style.transform = "translateY(-50%)";
button.style.padding = "80px 200px";
button.style.fontSize = "30px";
button.style.backgroundColor = "2ee649";
button.style.color = "d08de0";
button.style.border = "none";
button.style.borderRadius = "5px";
button.style.cursor = "pointer";
button.style.zIndex = "10000";
// 添加悬停效果
button.style.transition = "background-color 0.3s";
button.addEventListener('mouseover', () => {
if (!isRunning) {
button.style.backgroundColor = "#005f87";
}
});
button.addEventListener('mouseout', () => {
if (!isRunning) {
button.style.backgroundColor = "#007baf";
}
});
// 要点击的XPath数组
const xpaths = [
'//*[@id="radix-:r9:"]/div[2]/div[1]/section/div/div/div[2]/div[1]/article[2]/div[2]/div[1]/div[2]/button',
'//*[@id="radix-:r9:"]/div[2]/div[1]/section/div/div/div[2]/div[1]/article[2]/div[2]/div[2]/div[2]/button',
'//*[@id="radix-:r9:"]/div[2]/div[1]/section/div/div/div[2]/div[1]/article[2]/div[2]/div[3]/div[2]/button',
'//*[@id="radix-:r9:"]/div[2]/div[1]/section/div/div/div[2]/div[1]/article[2]/div[2]/div[4]/div[2]/button',
'//*[@id="radix-:r9:"]/div[2]/div[1]/section/div/div/div[2]/div[1]/article[2]/div[2]/div[5]/div[2]/button',
'//*[@id="radix-:r9:"]/div[2]/div[1]/section/div/div/div[2]/div[1]/article[2]/div[2]/div[6]/div[2]/button',
'//*[@id="radix-:r9:"]/div[2]/div[1]/section/div/div/div[2]/div[1]/article[2]/div[2]/div[7]/div[2]/button',
'//*[@id="radix-:r9:"]/div[2]/div[1]/section/div/div/div[2]/div[1]/article[2]/div[2]/div[8]/div[2]/button',
'//*[@id="radix-:r9:"]/div[2]/div[1]/section/div/div/div[2]/div[1]/article[2]/div[2]/div[9]/div[2]/button',
'//*[@id="radix-:r9:"]/div[2]/div[1]/section/div/div/div[2]/div[1]/article[2]/div[2]/div[10]/div[2]/button'
];
// 定义单次点击十个按钮的函数
async function clickElementsOnce() {
for (const xpath of xpaths) {
try {
// 查找元素
const element = document.evaluate(
xpath,
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
if (element) {
// 点击元素
element.click();
console.log(`已点击: ${xpath}`);
} else {
console.log(`未找到元素: ${xpath}`);
}
} catch (error) {
console.error(`处理${xpath}时出错:`, error);
}
// 每个按钮之间等待0.8秒
await new Promise(resolve => setTimeout(resolve, 800));
}
}
// 控制循环的函数
function toggleLoop() {
if (isRunning) {
// 停止循环
clearInterval(intervalId);
button.textContent = "甩狙";
button.style.backgroundColor = "#007baf";
console.log("已停止循环");
} else {
// 开始循环
button.textContent = "停止";
button.style.backgroundColor = "#dc3545"; // 红色表示运行中
console.log("开始循环点击");
// 立即执行一次,然后设置循环
clickElementsOnce();
// 设置循环,每次循环完成后等待3秒
intervalId = setInterval(() => {
clickElementsOnce();
}, 3000 + (xpaths.length * 800)); // 3秒加上点击10个按钮的总时间
}
isRunning = !isRunning;
}
// 给按钮添加点击事件
button.addEventListener('click', toggleLoop);
// 将按钮添加到页面
document.body.appendChild(button);
Loading…
Cancel
Save