// ==UserScript== // @name 课程自动学习 // @namespace http://tampermonkey.net/ // @version 2.2 // @description 普通版:数字教师、北京师范大学 2026年“国培计划”教师智能素养全员提升示范培训项目自动学习 // @match *://video.edueva.org/* // @run-at document-idle // @grant none // ==/UserScript== (function () { 'use strict'; const STORAGE_KEY = 'auto_course_run'; let timer = null; // 持久化运行状态 function saveRunning(flag) { try { localStorage.setItem(STORAGE_KEY, flag ? '1' : '0'); } catch (e) {} } function getRunning() { try { return localStorage.getItem(STORAGE_KEY) === '1'; } catch (e) { return false; } } // 模拟原生点击(沿用你原来的点击方式,这个对平台有效) function triggerClick(el) { if (!el) return; try { el.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true })); el.dispatchEvent(new MouseEvent('mousedown', { bubbles: true })); el.dispatchEvent(new MouseEvent('mouseup', { bubbles: true })); } catch (e) {} } // 原来:严格全等匹配,给【是】继续用(这个是稳定有效的) function findClickableExact(text) { const all = document.querySelectorAll('button, a, div, span'); for (let el of all) { if ((el.innerText || '').trim() === text) { if (el.children.length === 0) return el; return el; } } return null; } // 新增:包含匹配,专门给【我在】用,兼容文字嵌套子元素 function findClickableInclude(keyword) { const all = document.querySelectorAll('button, a, div, span'); for (let el of all) { const txt = (el.innerText || '').trim(); if (txt.includes(keyword)) { return el; } } return null; } function clickVerify() { try { // 这里改成包含匹配找我在 const el = findClickableInclude('我在'); if (el) { triggerClick(el); console.log('[挂机] 点击:我在'); } } catch (e) {} } function clickYesDialog() { try { // “是”继续使用原来的精确匹配,保持稳定 const el = findClickableExact('是'); if (el) { triggerClick(el); console.log('[挂机] 点击:是'); } } catch (e) {} } function resumeVideo() { try { const video = document.querySelector('video'); if (!video) return; video.muted = true; if (video.paused) { video.play().catch(() => {}); console.log('[挂机] 尝试恢复播放'); } // 兜底点击播放器中央大播放按钮 const bigBtn = document.querySelector('.vjs-big-play-button, [class*="big-play"], [class*="play-button"]'); if (bigBtn && video.paused) triggerClick(bigBtn); } catch (e) {} } function mainTask() { clickVerify(); clickYesDialog(); resumeVideo(); } function start() { if (timer) return; timer = setInterval(mainTask, 1000); saveRunning(true); console.log('[挂机] ✅ 已启动,切集后会自动续跑'); updateBtn(); } function stop() { if (timer) clearInterval(timer); timer = null; saveRunning(false); console.log('[挂机] ⏹ 已停止'); updateBtn(); } function updateBtn() { let btn = document.getElementById('auto-course-btn'); if (!btn) { btn = document.createElement('button'); btn.id = 'auto-course-btn'; btn.style.cssText = 'position:fixed;top:10px;right:10px;z-index:999999;padding:6px 12px'; document.body.appendChild(btn); btn.onclick = () => timer ? stop() : start(); } btn.innerText = timer ? '停止挂机' : '启动挂机'; } function waitBody() { if (document.body) { updateBtn(); // 页面刷新后按上次状态自动恢复 if (getRunning()) start(); return; } setTimeout(waitBody, 100); } waitBody(); })();