// ==UserScript== // @name 煤炭行业现代远程教育培训网自动播放下一节视频(2026年7月精确稳定版) // @namespace http://tampermonkey.net/ // @version 0.7 // @description 自动播放 + 精确识别当前课程 + 自动下一节 + 5分钟卡死检测和自动刷新进度 // @author yhr + ChatGPT // @match https://www.coaledu.net/*/coursePlay.html* // @run-at document-end // @require https://code.jquery.com/jquery-3.6.0.min.js // @grant GM_notification // ==/UserScript== this.$ = this.jQuery = jQuery.noConflict(true); (function () { 'use strict'; let lastClickTime = 0; let refreshTimer = null; /** ====================== * 1. 关闭弹窗/遮罩 * ====================== */ setInterval(function () { $("span:contains('继续')").each(function () { const btn = $(this).parent("button"); if (btn.is(":visible")) btn.click(); }); $(".verifyFaceMask").hide(); $(".ccMask").hide(); }, 1000); /** ====================== * 2. 主播放逻辑 * ====================== */ setInterval(function () { const current = $("a.nowrap.on.subset-class"); if (!current.length) return; autoPlay(current); }, 3000); 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 video = document.querySelector("video"); if (video && video.paused) video.play().catch(() => {}); const playBtn = $(".ccH5PlayBtn"); if (playBtn.is(":visible")) playBtn.click(); }, 1200); return; } const next = li.nextAll("li").first().find("a.nowrap.subset-class"); if (next.length) { next[0].click(); lastClickTime = now; setTimeout(() => { const video = document.querySelector("video"); if (video && video.paused) video.play().catch(() => {}); }, 1200); } else { GM_notification({ text: "全部课程完成", title: "学习结束" }); } } /** ====================== * 3. 5分钟卡死恢复(优化版) * ====================== */ 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; } if (stuckCount > 30) { console.log("5分钟无进度,恢复播放"); stuckCount = 0; const video = document.querySelector("video"); if (video) video.play().catch(() => {}); const playBtn = $(".ccH5PlayBtn"); if (playBtn.is(":visible")) playBtn.click(); } }, 10000); /** ====================== * 4. 风控弹窗处理 * ====================== */ setInterval(function () { const box = document.querySelector(".playback-guard-message-box"); if (box && box.offsetParent !== null) { const btn = box.querySelector(".el-button--primary"); if (btn) btn.click(); setTimeout(() => { const video = document.querySelector("video"); if (video) video.play().catch(() => {}); const playBtn = $(".ccH5PlayBtn"); if (playBtn.is(":visible")) playBtn.click(); }, 2000); } }, 2000); setInterval(function () { const btn = document.querySelector(".info-button.watch"); if (btn && btn.offsetParent !== null) { console.log("🎯 点击立即观看"); setTimeout(() => { btn.click(); }, 500); } }, 1500); /** ====================== * 5. 每4-6分钟循环刷新页面(优化版) * ====================== */ function getRandomRefreshTime() { const minMinutes = 4; const maxMinutes = 6; const minMs = minMinutes * 60 * 1000; const maxMs = maxMinutes * 60 * 1000; return Math.floor(Math.random() * (maxMs - minMs + 1)) + minMs; } function scheduleRefresh() { // 清除旧定时器 if (refreshTimer) { clearTimeout(refreshTimer); refreshTimer = null; } const delay = getRandomRefreshTime(); console.log(`⏰ 下次刷新将在 ${Math.round(delay / 60000)} 分钟后刷新`); refreshTimer = setTimeout(() => { console.log("🔄 执行页面刷新"); location.reload(); }, delay); } // 启动刷新循环 scheduleRefresh(); })();