// ==UserScript== // @name 煤炭行业现代远程教育培训网自动播放下一节视频(2026年7月精确稳定版) // @namespace http://tampermonkey.net/ // @version 0.6 // @description 自动播放 + 精确识别当前课程 + 自动下一节 + 10分钟卡死检测(稳定优化版) // @author yhr + ChatGPT // @match https://www.coaledu.net/*/coursePlay.html* // @run-at document-end // @require https://code.jquery.com/jquery-1.12.4.min.js // @grant GM_notification // ==/UserScript== this.$ = this.jQuery = jQuery.noConflict(true); (function () { 'use strict'; let lastClickTime = 0; /** ====================== * 1. 关闭“继续学习”弹窗 * ====================== */ setInterval(function () { $("span:contains('继续')").each(function () { const btn = $(this).parent("button"); if (btn.is(":visible")) { btn.click(); } }); }, 1000); /** ====================== * 2. 主循环(更精确:只处理当前播放项) * ====================== */ setInterval(function () { const current = $("a.nowrap.on.subset-class"); if (!current.length) return; autoPlay(current); }, 4000); function autoPlay(current) { const now = Date.now(); if (now - lastClickTime < 1200) return; const li = current.closest("li"); // ⭐ 精确读取当前这一条的进度 const percentText = li.find(".finish-percent").first().text().trim(); const percent = parseFloat(percentText) || 0; // ====================== // 未完成:继续播放当前 // ====================== if (percent < 100) { current[0].click(); lastClickTime = now; setTimeout(() => { const playBtn = $(".ccH5PlayBtn"); if (playBtn.is(":visible")) { playBtn.click(); } }, 1500); return; } // ====================== // 已完成:自动下一节(更精确 nextAll) // ====================== const next = li.nextAll("li").first().find("a.nowrap.subset-class"); if (next.length) { next[0].click(); lastClickTime = now; setTimeout(() => { const playBtn = $(".ccH5PlayBtn"); if (playBtn.is(":visible")) { playBtn.click(); } }, 1500); } else { GM_notification({ text: "全部课程已完成", title: "学习结束" }); } } /** ====================== * 3. 卡死检测(10分钟精确版) * ====================== */ let lastProgress = null; let stuckCount = 0; setInterval(function () { // ⭐ 只看“当前播放项” const currentLi = $("a.nowrap.on.subset-class").closest("li"); if (!currentLi.length) return; const percentText = currentLi.find(".finish-percent").first().text().trim(); const currentProgress = parseFloat(percentText) || 0; if (lastProgress === null) { lastProgress = currentProgress; return; } if (currentProgress === lastProgress) { stuckCount++; } else { stuckCount = 0; lastProgress = currentProgress; } // ⭐ 10分钟 = 60次(每10秒检测一次) if (stuckCount > 60) { console.log("检测到10分钟无进度变化,尝试恢复播放..."); stuckCount = 0; // 不直接暴力刷新,先尝试恢复播放 const playBtn = $(".ccH5PlayBtn"); if (playBtn.is(":visible")) { playBtn.click(); } else { location.reload(); } } }, 10000); /** ====================== * 4. 播放结束兜底 * ====================== */ setInterval(function () { const replayBtn = $("div.adrPlayBtn"); if (replayBtn.is(":visible")) { replayBtn.click(); } }, 5000); })();