学习公社-20分钟自动点击

每隔20分钟自动点击弹出框确定按钮

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         学习公社-20分钟自动点击
// @namespace    https://study.enaea.edu.cn/
// @version      1.1
// @description  每隔20分钟自动点击弹出框确定按钮
// @match        https://study.enaea.edu.cn/*
// @grant        none
// @license      MIT    
// ==/UserScript==

function checkAndClickButton() {
    // 查询页面上是否存在特定的按钮
    const button = document.querySelector('button[style*="background-color: rgb(192, 19, 13)"]');
    if (button) {
        // 生成一个介于3000毫秒(3秒)到15000毫秒(15秒)之间的随机延时
        let delay = Math.floor(Math.random() * (15000 - 3000 + 1) + 3000);
        console.log(`找到按钮,将在 ${delay / 1000} 秒后自动点击...`);
        
        // 使用setTimeout来实现延时点击
        setTimeout(() => {
            console.log('正在点击按钮...');
            button.click();
        }, delay);
    } 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('观察者已激活,继续等待按钮出现...');