// ==UserScript== // @name 华医网播放页自动化 // @namespace http://tampermonkey.net/ // @version 2.0 // @description 自动签到、异常刷新并点击第一节课、卡顿刷新 // @match *://zppx.91huayi.com/exercise/ExerciseCourse/CoursePlay* // @grant none // @run-at document-idle // ==/UserScript== (function() { 'use strict'; // 1. 自动点击签到框 function autoSign() { const signBtn = document.querySelector('.ccSignWrapBtn'); if (signBtn) { signBtn.click(); console.log('[Tampermonkey] 已自动点击签到'); } } // 2. 视频卡顿自动刷新 function checkVideoStuck() { const video = document.querySelector('video'); if (!video) return; let lastTime = video.currentTime; setInterval(() => { // 播放中、进度没变、且视频已准备好 if (!video.paused && video.currentTime === lastTime && video.readyState >= 3) { console.log('[Tampermonkey] 检测到视频卡顿,正在刷新...'); window.location.reload(); } lastTime = video.currentTime; }, 5000); } // 3. 终极异常检测与刷新后点击 function initErrorObserver() { // 第一步:处理刷新后的点击逻辑 if (localStorage.getItem('needClickFirstCourse') === 'true') { localStorage.removeItem('needClickFirstCourse'); console.log('[Tampermonkey] 检测到刷新标记,准备点击第一节课...'); setTimeout(() => { const firstCourse = document.querySelector('.listGroup .listItem:first-child .text'); if (firstCourse) { firstCourse.click(); console.log('[Tampermonkey] 已自动点击:' + firstCourse.textContent); } else { console.warn('[Tampermonkey] 未找到课程列表,请检查页面结构'); } }, 1500); // 等待1.5秒让列表加载 } // 第二步:启动 DOM 监听器,死死盯住页面变化 const observer = new MutationObserver(() => { const errorMsg = document.querySelector('#msgContent'); // 只要包含“异常”二字即触发,防止空格或换行导致匹配失败 if (errorMsg && errorMsg.textContent.includes('异常')) { console.log('[Tampermonkey] 监听器捕获到异常提示,2秒后刷新...'); observer.disconnect(); // 立即停止监听,防止重复触发刷新 localStorage.setItem('needClickFirstCourse', 'true'); setTimeout(() => window.location.reload(), 2000); } }); // 监听整个 body 的子节点和文本变化 observer.observe(document.body, { childList: true, subtree: true }); } // 启动所有功能 setInterval(autoSign, 3000); checkVideoStuck(); initErrorObserver(); })();