// ==UserScript== // @name 武汉讯网网课自动切换下一节 (精准DOM提取版) // @namespace http://tampermonkey.net/ // @version 1.1 // @description 监控课程播放进度,通过DOM精准提取时间,相等时自动跳转到下一节 // @author Developer // @match *://0155.whxunw.com/* // @grant none // @license MIT // ==/UserScript== (function () { 'use strict'; // 用于存储当前正在监控的课时ID,防止重复点击 let currentLessonId = null; // 核心逻辑:检查进度并切换 function checkProgressAndSwitch() { // 1. 找到当前正在播放的课时项 (带有 .play 类的 li 元素) const currentPlayingLesson = document.querySelector('li.pointer.play'); if (!currentPlayingLesson) { return; } // 2. 获取当前课时的唯一标识,用于防止重复点击 const lessonUniqueId = currentPlayingLesson.outerHTML; if (currentLessonId === lessonUniqueId) { return; } // 3. 在当前课时项中,找到 class="progress_info" 的容器 const progressContainer = currentPlayingLesson.querySelector('span.progress_info'); if (!progressContainer) { return; } // 4. 【核心优化】:直接通过 DOM 提取第一个和第二个 span 的文本 const allSpans = progressContainer.querySelectorAll('span'); if (allSpans.length < 2) { console.log('[自动切换] 进度节点内未找到足够的时间标签,跳过检测'); return; } // 第一个 span 是已播放时间,第二个 span 是总时间 const playedTime = parseInt(allSpans[0].textContent.trim(), 10); const totalTime = parseInt(allSpans[1].textContent.trim(), 10); // 防止提取到 NaN if (isNaN(playedTime) || isNaN(totalTime)) { console.warn('[自动切换] 提取到的时间不是有效数字,跳过检测'); return; } // 【每次检测都打印当前进度与总时间】 console.log(`[自动切换] 正在检测当前课程进度... 当前进度: ${playedTime} / ${totalTime}`); // 5. 核心判断:如果已播放时间等于总时间,说明课程已结束 if (playedTime === totalTime) { console.log('[自动切换] 课程已完成,正在寻找下一节...'); // 6. 获取所有可点击的课时列表 const allLessons = document.querySelectorAll('li.pointer'); const currentIndex = Array.from(allLessons).indexOf(currentPlayingLesson); const nextIndex = currentIndex + 1; // 7. 检查是否存在下一节课 if (nextIndex < allLessons.length) { const nextLesson = allLessons[nextIndex]; console.log(`[自动切换] 找到下一节课,准备点击: ${nextLesson.textContent.trim()}`); // 执行点击 nextLesson.click(); // 更新当前课时ID,防止重复点击 currentLessonId = lessonUniqueId; } else { console.log('[自动切换] 恭喜!已经是最后一节课了。'); } } } // 使用定时器,每隔一段时间检查一次进度 // 设置为5秒检查一次,反应比较及时且不影响性能 setInterval(checkProgressAndSwitch, 5000); console.log('[自动切换] 脚本已启动,正在监控课程进度...'); })();