// ==UserScript== // @name 山东省教师教育网 · 自动连播助手(免费加强版) // @namespace lm4217 // @version 4.0.1 // @description 免费版学习助手:自动播放下一个视频、看完自动连播下一节、自动完成测试题。想更快刷完整期研修,请用独立 VIP 版。 // @author lm4217 // @license MIT // @match *://yxjc.qlteacher.com/project/* // @match *://player.qlteacher.com/learning/* // @grant none // @run-at document-end // @antifeature payment // @tag 教育 // @tag 学习辅助 // ==/UserScript== (() => { 'use strict'; const BUY_URL = 'https://wzyp.cn/item/i9awt5'; const CFG = { pollMs: 4000, // 查询活动状态的间隔 videoWaitMs: 2500, // 找 video 元素的重试步长 answerGapMs: 800, // 两轮答题之间的间隔 jumpGapMs: 1200, // 跳转到下一节前的缓冲 maxSameActMs: 4 * 3600 * 1000, // 单个活动最长蹲守时间,防止死循环 }; // VIP 版在工作时让位,避免两个面板叠加 function vipRunning() { if (window.__LCS_PAID__) return true; try { if (/(?:^|; )lcs_paid=/.test(document.cookie)) return true; } catch (e) {} return !!document.getElementById('lcs-dot'); } const HOST = location.hostname; const isLearnPage = HOST === 'yxjc.qlteacher.com' && /^\/(?:pre-)?project\/[A-Za-z0-9]+\/lesson\/learn/.test(location.pathname); const isPlayerPage = HOST === 'player.qlteacher.com' && /^\/learning\//.test(location.pathname); if (!isLearnPage && !isPlayerPage) return; if (document.getElementById('qlt-free-helper')) return; if (vipRunning()) return; const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); const nowTs = () => Date.now(); function projectId() { const m = location.pathname.match(/\/(?:pre-)?project\/([A-Za-z0-9]+)/); return m ? m[1] : ''; } function courseIdFromPath() { const m = location.pathname.match(/\/learning\/([A-Za-z0-9]+)/); return m ? m[1] : ''; } function actIdFromPath() { const m = location.pathname.match(/\/learning\/[A-Za-z0-9]+\/([A-Za-z0-9]+)/); return m ? m[1] : ''; } function authHeaders() { try { const tok = JSON.parse(localStorage.getItem('qlt_token') || '{}'); if (tok && tok.access_token) return { Authorization: 'Bearer ' + tok.access_token }; } catch (e) {} return {}; } async function jreq(url, opts = {}) { const r = await fetch(url, { credentials: 'include', ...opts, headers: { ...authHeaders(), ...(opts.headers || {}) }, }); const text = await r.text(); let json = null; try { json = JSON.parse(text); } catch (e) {} return { status: r.status, json, text }; } const jget = (url) => jreq(url); const jpost = (url, body) => jreq(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body), }); // ---------- 面板 ---------- const hud = { root: null, dot: null, state: null, sub: null, bar: null, log: null, toggle: null }; function buildHud() { const panel = document.createElement('div'); panel.id = 'qlt-free-helper'; panel.style.cssText = 'position:fixed;right:18px;bottom:20px;z-index:2147483646'; const root = panel.attachShadow({ mode: 'open' }); root.innerHTML = `

自动连播助手 免费版

自动播下一节 · 自动答题 · 不用守着电脑

正在识别页面
省心省电费,1 分钟速刷整期研修
免费版得把每节课按时长播完,一期课要熬好几个小时。
VIP 版不用陪视频走完时长,整期研修一分钟结束,电脑也不用整晚开着。
获取 VIP 版 · 一分钟刷完
免费版不含加速功能。
`; (document.body || document.documentElement).appendChild(panel); hud.root = root; hud.dot = root.getElementById('dot'); hud.state = root.getElementById('state'); hud.sub = root.getElementById('sub'); hud.bar = root.getElementById('bar'); hud.log = root.getElementById('logs'); hud.toggle = root.getElementById('pause'); root.getElementById('collapse').onclick = (e) => { const bd = root.getElementById('body'); const hidden = bd.classList.toggle('hide'); e.currentTarget.textContent = hidden ? '▴' : '▾'; }; root.getElementById('buy').href = BUY_URL; } function setState(text, tone) { if (!hud.state) return; hud.state.textContent = text; hud.dot.dataset.s = tone || 'ok'; } function setSub(text) { if (hud.sub) hud.sub.textContent = text || ''; } function setBar(pct) { if (hud.bar) hud.bar.style.width = Math.max(0, Math.min(100, pct)) + '%'; } function log(msg) { if (!hud.log) return; const d = document.createElement('div'); d.textContent = new Date().toLocaleTimeString('zh-CN', { hour12: false }) + ' ' + msg; hud.log.appendChild(d); while (hud.log.childElementCount > 40) hud.log.removeChild(hud.log.firstElementChild); hud.log.scrollTop = hud.log.scrollHeight; } const state = { enabled: true, stop: false, running: false }; // ---------- 课程列表页 ---------- function collectLessons(payload) { const out = []; (function walk(n) { if (!n) return; if (Array.isArray(n)) { n.forEach(walk); return; } if (typeof n !== 'object') return; if (n.id && n.name && Object.prototype.hasOwnProperty.call(n, 'lessonLearnStatus')) { const s = n.lessonLearnStatus || {}; if (n.allowLearn !== false) { out.push({ id: n.id, name: n.name, status: s.status, hour: n.learnHour || 0 }); } } Object.keys(n).forEach((k) => walk(n[k])); })(payload); return out; } async function runLearnPage() { state.running = true; const pid = projectId(); setState('读取课程清单', 'ok'); setSub('项目 ' + pid); const r = await jget(`https://yxjc.qlteacher.com/api//lesson/lessons/my?projectId=${encodeURIComponent(pid)}`); const lessons = collectLessons(r.json && r.json.data); if (!lessons.length) { setState('没有读到课程', 'warn'); setSub('确认已报名并进入正确项目'); return; } const todo = lessons.filter((x) => x.status !== 1); const done = lessons.length - todo.length; setBar((done / lessons.length) * 100); log(`课程 ${done}/${lessons.length} 已完成`); if (!todo.length) { setState('全部课程已完成', 'ok'); setSub(`${lessons.length} 门课都学完了`); return; } // 防止「跳过去→没进展→又跳回来」的打转 const guardKey = 'qlt_free_jump_' + pid; let last = null; try { last = JSON.parse(sessionStorage.getItem(guardKey) || 'null'); } catch (e) {} if (last && last.id === todo[0].id && nowTs() - last.t < 20000) { setState('刚才已跳转过', 'warn'); setSub('等一会儿再刷新,或手动点进课程'); return; } const target = todo[0]; setState('准备进入:' + target.name.slice(0, 14), 'ok'); setSub(`待学 ${todo.length} 门`); const u = await jget(`https://yxjc.qlteacher.com/api//lesson/learning/url?projectId=${encodeURIComponent(pid)}&lessonId=${encodeURIComponent(target.id)}`); const url = (u.json && u.json.data) || ''; if (!/\/learning\/[A-Za-z0-9]+/.test(url)) { setState('无法进入课程', 'err'); setSub('接口没有返回播放地址'); return; } try { sessionStorage.setItem(guardKey, JSON.stringify({ id: target.id, t: nowTs() })); } catch (e) {} log('进入 ' + target.name.slice(0, 16)); setState('跳转播放页…', 'ok'); await sleep(600); location.href = url; } // ---------- 播放页 ---------- const P = 'https://player.qlteacher.com/api/learning/'; function listActivities(payload) { const out = []; const seen = {}; (function walk(n) { if (!n) return; if (Array.isArray(n)) { n.forEach(walk); return; } if (typeof n !== 'object') return; if (n.id && n.sessionType && !seen[n.id]) { seen[n.id] = 1; out.push({ id: n.id, type: n.sessionType, title: n.title || '', studyTime: (n.ext && n.ext.studyTime) || 0, plus: !!n.plus, }); } Object.keys(n).forEach((k) => walk(n[k])); })(payload); return out; } async function activityMeta(cid, actId) { const r = await jget(P + cid + '/activity/' + actId); const d = (r.json && r.json.data) || {}; return { status: d.status, duration: d.duration, studyTime: d.activity && d.activity.ext && d.activity.ext.studyTime, title: d.activity && d.activity.title, sessionType: d.activity && d.activity.sessionType, items: (d.activity && d.activity.ext && d.activity.ext.examItems) || [], userAnswers: d.userAnswers || [], }; } // 自动答题:先按保守答案交一轮,再用回传的标准答案交一轮拿满分 async function autoAnswer(cid, actId, meta) { const items = meta.items; if (!items.length) return true; const prev = meta.userAnswers; if (prev.length === items.length && prev.every((x) => x.correct)) { log('测试题此前已满分'); return true; } const guess = items.map((q) => { const opts = (q.options || []).map((o) => o.id); const single = q.type === 'SINGLE' || q.type === 'TRUEORFALSE'; return { questionId: q.id, answer: single ? opts[0] : opts.join(',') }; }); setSub('答题中:' + items.length + ' 题'); const first = await jpost(P + cid + '/test', { token: cid, activityId: actId, answers: guess }); const d1 = (first.json && first.json.data) || {}; const total = items.length; const got1 = d1.rightCount; log(`答题第一轮 ${got1 == null ? '?' : got1}/${total}`); if (got1 === total) return true; const map = d1.answers || {}; const fixed = Object.keys(map) .filter((qid) => map[qid] && map[qid].rightAnswer) .map((qid) => ({ questionId: qid, answer: map[qid].rightAnswer })); if (!fixed.length) { log('未取到标准答案,保留本轮作答'); return true; } await sleep(CFG.answerGapMs); const second = await jpost(P + cid + '/test', { token: cid, activityId: actId, answers: fixed }); const d2 = (second.json && second.json.data) || {}; log(`答题第二轮 ${d2.rightCount == null ? '?' : d2.rightCount}/${total}`); return true; } // 页面里的 video,同源 iframe 也找一遍 function findVideo() { const seen = []; function scan(doc) { if (!doc || seen.includes(doc)) return null; seen.push(doc); const v = doc.querySelector('video'); if (v) return v; for (const f of doc.querySelectorAll('iframe')) { try { const got = scan(f.contentDocument); if (got) return got; } catch (e) { /* 跨域读不到就跳过 */ } } return null; } return scan(document) || null; } async function ensurePlaying() { const v = findVideo(); if (!v) return false; if (v.paused) { v.muted = true; try { await v.play(); } catch (e) { return false; } } return true; } async function waitVideoDone(cid, actId, deadline) { let lastDur = -1; while (nowTs() < deadline && !state.stop) { const m = await activityMeta(cid, actId); if (m.status === 1) return true; if (m.duration != null && m.studyTime) { setBar((m.duration / m.studyTime) * 100); if (m.duration !== lastDur) { lastDur = m.duration; setSub(`已看 ${m.duration}/${m.studyTime} 秒`); } } await ensurePlaying(); await sleep(CFG.pollMs); } return false; } function gotoNext(cid, actId) { location.href = 'https://player.qlteacher.com/learning/' + cid + '/' + actId; } function backToLearn() { const pid = projectId() || ''; const m = document.referrer && /\/project\/([A-Za-z0-9]+)\//.exec(document.referrer); const usePid = pid || (m && m[1]) || ''; if (usePid) { location.href = `https://yxjc.qlteacher.com/project/${usePid}/lesson/learn`; } else { setState('本课程结束', 'ok'); setSub('回到课程列表可继续下一门'); } } async function runPlayerPage() { state.running = true; const cid = courseIdFromPath(); if (!cid) { setState('无法识别课程', 'err'); return; } setState('读取课程结构', 'ok'); const cr = await jget(P + cid + '/course'); const acts = listActivities(cr.json && cr.json.data); if (!acts.length) { setState('课程结构为空', 'warn'); return; } const curAct = actIdFromPath(); let idx = acts.findIndex((a) => a.id === curAct); if (idx < 0) idx = 0; for (let i = idx; i < acts.length; i++) { if (state.stop) return; const a = acts[i]; setBar((i / acts.length) * 100); setSub(`第 ${i + 1}/${acts.length} 节 · ${a.type}`); const m = await activityMeta(cid, a.id); if (m.status === 1) { log('已跳过:' + (a.title || a.id).slice(0, 14)); continue; } if (a.id !== actIdFromPath()) { setState('切换:' + (a.title || a.type).slice(0, 14), 'ok'); log('进入 ' + (a.title || a.type).slice(0, 14)); if (!state.enabled) { setState('已暂停', 'off'); return; } await sleep(CFG.jumpGapMs); gotoNext(cid, a.id); return; // 页面重载后由新实例接着跑 } if (a.type === 'exam') { setState('自动答题', 'ok'); await autoAnswer(cid, a.id, m); await sleep(CFG.answerGapMs); continue; } if (a.type === 'video') { setState('正在播放:' + (a.title || '').slice(0, 14), 'ok'); log('播放 ' + (a.title || '').slice(0, 14)); const deadline = nowTs() + Math.min(CFG.maxSameActMs, ((m.studyTime || 600) + 300) * 1000); const done = await waitVideoDone(cid, a.id, deadline); if (state.stop) return; if (!done) { setState('本节未完成', 'warn'); setSub('可能被暂停了,稍后自动重试'); await sleep(3000); return; } log('完成:' + (a.title || '').slice(0, 14)); continue; } setState('浏览:' + (a.title || a.type).slice(0, 14), 'ok'); log('打开 ' + (a.type || '资源').slice(0, 8)); await sleep(CFG.videoWaitMs); } setBar(100); setState('本课程已处理完', 'ok'); log('返回课程列表'); await sleep(CFG.jumpGapMs); if (state.enabled) backToLearn(); } // ---------- 启动 ---------- function boot() { buildHud(); hud.toggle.onclick = () => { state.enabled = !state.enabled; hud.toggle.textContent = state.enabled ? '暂停自动连播' : '继续自动连播'; if (!state.enabled) { state.stop = true; setState('已暂停自动连播', 'off'); } else { state.stop = false; setState('继续工作', 'ok'); location.reload(); } }; hud.root.getElementById('skipnow').onclick = () => { if (!courseIdFromPath()) return; log('手动跳过当前节'); state.stop = true; location.reload(); }; setState('准备就绪', 'ok'); if (isLearnPage) { runLearnPage().catch((e) => { setState('运行出错', 'err'); setSub(String((e && e.message) || e)); }); } else { runPlayerPage().catch((e) => { setState('运行出错', 'err'); setSub(String((e && e.message) || e)); }); } } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', boot, { once: true }); } else { boot(); } })();