// ==UserScript== // @name 火鸟快速抽卡脚本(优化版) // @namespace https://scriptcat.org/zh-CN/users/171872 // @version 1.3 // @description 安装后,在抽卡界面刷新一下脚本就会启动; // @author Cc // @match https://*.in/gaming/genshin/character/draw // @grant none // ==/UserScript== (function() { 'use strict'; // 配置参数:可在此修改 const DEFAULT_INTERVAL_MS = 5000; // 默认间隔时间(毫秒) let intervalMs = DEFAULT_INTERVAL_MS; // 变量状态 let intervalId = null; let clickCount = 0; // 创建控制面板 const panel = document.createElement('div'); Object.assign(panel.style, { position: 'fixed', top: '50%', right: '10px', transform: 'translateY(-50%)', background: 'rgba(0,0,0,0.6)', color: '#fff', padding: '12px 16px', borderRadius: '8px', zIndex: 9999, userSelect: 'none', fontSize: '14px', width: '160px', textAlign: 'center', boxShadow: '0 0 10px rgba(0,0,0,0.5)', fontFamily: 'Arial, sans-serif' }); // 标题 const title = document.createElement('div'); title.textContent = '火鸟快速抽卡脚本'; title.style.fontWeight = 'bold'; title.style.marginBottom = '8px'; panel.appendChild(title); // 控制按钮容器 const btnContainer = document.createElement('div'); btnContainer.style.marginBottom = '8px'; // 启动按钮 const startBtn = document.createElement('button'); startBtn.textContent = '启动'; Object.assign(startBtn.style, { marginRight: '8px', cursor: 'pointer', padding: '6px 12px', border: 'none', borderRadius: '4px', backgroundColor: '#4CAF50', color: 'white', fontWeight: 'bold' }); // 停止按钮 const stopBtn = document.createElement('button'); stopBtn.textContent = '停止'; Object.assign(stopBtn.style, { cursor: 'pointer', padding: '6px 12px', border: 'none', borderRadius: '4px', backgroundColor: '#f44336', color: 'white', fontWeight: 'bold' }); stopBtn.disabled = true; // 初始禁用 btnContainer.appendChild(startBtn); btnContainer.appendChild(stopBtn); panel.appendChild(btnContainer); // 间隔时间调节 const intervalContainer = document.createElement('div'); intervalContainer.style.marginBottom = '8px'; const intervalLabel = document.createElement('label'); intervalLabel.textContent = '间隔秒数:'; intervalLabel.style.marginRight = '6px'; const intervalInput = document.createElement('input'); intervalInput.type = 'number'; intervalInput.min = '1'; intervalInput.value = (DEFAULT_INTERVAL_MS / 1000).toString(); // 设置字体颜色为黑色,背景为白色,确保清晰 Object.assign(intervalInput.style, { width: '50px', color: '#000', // 黑色字体 backgroundColor: '#fff', // 白色背景 border: '1px solid #ccc', borderRadius: '4px', padding: '2px 4px', fontSize: '14px' }); intervalContainer.appendChild(intervalLabel); intervalContainer.appendChild(intervalInput); panel.appendChild(intervalContainer); // 点击次数显示 const countDisplay = document.createElement('div'); countDisplay.textContent = '点击次数: 0'; Object.assign(countDisplay.style, { fontSize: '13px', color: '#ffeb3b', userSelect: 'text' }); panel.appendChild(countDisplay); document.body.appendChild(panel); // 目标按钮XPath(请确保此路径正确,或考虑改用其他选择器) const targetXPath = "/html/body/div[1]/div/div/section/section/main/div[2]/div/div[2]/div/div[2]/div/div[2]/div[2]/div/div[1]/div[3]/div/div[2]/div[2]"; /** * 获取目标按钮元素 */ function getTargetElement() { return document.evaluate(targetXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; } /** * 执行点击操作 */ function clickTarget() { const btn = getTargetElement(); if (btn) { btn.click(); clickCount++; countDisplay.textContent = `点击次数: ${clickCount}`; console.log(`已点击 连抽十次 按钮, 总计: ${clickCount} 次`); } else { console.warn('未找到 连抽十次 按钮'); } } /** * 启动自动点击 */ function startAutoClick() { if (intervalId) return; // 已在运行 // 读取最新的间隔时间 const seconds = parseInt(intervalInput.value, 10); if (isNaN(seconds) || seconds < 1) { alert('请填写有效的间隔秒数(大于0)'); return; } intervalMs = seconds * 1000; // 重置计数 clickCount = 0; countDisplay.textContent = `点击次数: ${clickCount}`; // 立即点击一次 clickTarget(); // 设置定时器 intervalId = setInterval(() => { clickTarget(); }, intervalMs); // 按钮状态切换 startBtn.disabled = true; stopBtn.disabled = false; console.log(`自动点击已启动,间隔 ${seconds} 秒`); } /** * 停止自动点击 */ function stopAutoClick() { if (intervalId) { clearInterval(intervalId); intervalId = null; startBtn.disabled = false; stopBtn.disabled = true; console.log('自动点击已停止'); } } // 事件绑定 startBtn.addEventListener('click', startAutoClick); stopBtn.addEventListener('click', stopAutoClick); // 支持快捷键(F8启动,F9停止) document.addEventListener('keydown', (e) => { if (e.key === 'F8') { startAutoClick(); } else if (e.key === 'F9') { stopAutoClick(); } }); })();