您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
检测指定图标是否存在,不存在则自动刷新页面
// ==UserScript== // @name gooboo刷新神秘碎片 // @namespace http://tampermonkey.net/ // @version 1.0 // @description 检测指定图标是否存在,不存在则自动刷新页面 // @author YourName // @match *://*/gooboo/* // @match https://gooboo.g8hh.com.cn/* // @grant unsafeWindow // @run-at document-end // ==/UserScript== (function() { 'use strict'; // 配置参数 ======================================== const config = { iconSelector: '.mdi-billiards-rack', // 修改为目标图标的选择器 checkInterval: 500, // 检查间隔(毫秒) maxRetries: 20, // 最大重试次数(可选防护) debugMode: true // 调试日志开关 }; // 核心逻辑 ======================================== let checkCount = 0; const checkIcon = () => { const targetElement = document.querySelector(config.iconSelector); log(`第 ${++checkCount} 次检查 - 目标元素: ${targetElement ? '存在' : '不存在'}`); // 元素存在时执行 if (targetElement) { log(' 检测到目标图标,停止刷新'); clearInterval(checkTimer); // 此处可添加检测到元素后的操作 return; } // 防护机制:达到最大重试次数 if (config.maxRetries && checkCount >= config.maxRetries) { log(' 达到最大重试次数,停止刷新'); clearInterval(checkTimer); return; } // 执行刷新 log(' 未检测到目标图标,执行刷新'); setTimeout(() => location.reload(), 1000); }; // 工具函数 ======================================== const log = (...args) => { if (config.debugMode) console.log('[图标检测]', ...args); }; // 启动检测 ======================================== log('脚本启动,配置参数:', config); const checkTimer = setInterval(checkIcon, config.checkInterval); })();