// ==UserScript== // @name 学习公社-20分钟自动点击 // @namespace https://study.enaea.edu.cn/ // @version 1.0 // @description 每隔20分钟自动点击弹出框确定按钮 // @match https://study.enaea.edu.cn/* // @grant none // @license MIT // @downloadURL none // ==/UserScript== function checkAndClickButton() { // 查询页面上是否存在特定的按钮 const button = document.querySelector('button[style*="background-color: rgb(192, 19, 13)"]'); if (button) { console.log('找到按钮,正在自动点击...'); button.click(); } else { console.log('当前没有找到指定的按钮。'); } } // 首先执行一次检查,以处理页面加载时已存在的按钮 checkAndClickButton(); // 创建一个观察器实例并传入回调函数 var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { mutation.addedNodes.forEach(node => { // 检查是否是元素节点,并且包含特定的按钮 if (node.nodeType === 1 && node.querySelector('button[style*="background-color: rgb(192, 19, 13)"]')) { checkAndClickButton(); } }); }); }); // 配置观察选项 var config = { childList: true, subtree: true }; // 选择需要观察变动的节点 var targetNode = document.body; // 调用 `observe` 方法开始观察选定的节点 observer.observe(targetNode, config); console.log('观察者已激活,继续等待按钮出现...');