// ==UserScript== // @name 山东省教师教育网-2026中小学远程研修 // @namespace http://tampermonkey.net/ // @version 2.6.2 // @description 2026课程倍速播放辅助:固定倍速、自动试速、后台播放状态观察;出现时长校验提示时自动停止操作。支持卡密激活完整学习引擎。 // @author alkaidccc, local adaptation // @license alkaidccc // @match *://yxjc.qlteacher.com/project/* // @match *://yxjc.qlteacher.com/pre-project/* // @match *://player.qlteacher.com/* // @grant none // @run-at document-end // ==/UserScript== (() => { 'use strict'; // ================================================================== // 授权层:卡密激活 -> 拉取完整引擎 -> 本地执行 // 未激活时只提供倍速与测速,不做任何自动播放动作。 // ================================================================== const LIC_HOSTS = [ 'https://lic.815111.xyz', 'https://auth.815111.xyz', ]; const K_LIC = 'lcs_lic'; const K_PKG = 'lcs_pkg'; const K_FP = 'lcs_fp'; const K_TRIAL = 'lcs_lic_ok_at'; const K_SYNC = 'lcs_sync'; const OFFLINE_GRACE = 3 * 86400 * 1000; // 授权状态必须跨 yxjc / player 两个子域共享:localStorage 按源隔离,两边读不到对方, // 所以状态落在 .qlteacher.com 的 cookie 上(引擎的单实例锁 lcs_lock 用的是同一手法)。 const CK_DOMAIN = '; domain=.qlteacher.com; path=/; SameSite=Lax'; function ckGet(name) { const m = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)')); if (!m) return null; try { return JSON.parse(decodeURIComponent(m[1])); } catch (e) { return null; } } function ckSet(name, v, days) { try { const raw = encodeURIComponent(JSON.stringify(v)); document.cookie = name + '=' + raw + CK_DOMAIN + (days ? '; max-age=' + Math.round(days * 86400) : ''); return true; } catch (e) { return false; } } function ckDel(name) { try { document.cookie = name + '=; domain=.qlteacher.com; path=/; max-age=0'; } catch (e) {} } // 读令牌:cookie 优先,回落 localStorage 以兼容升级前已经激活过的用户 function licGet() { const c = ckGet(K_LIC); if (c && c.token) return c; return lsGet(K_LIC); } function licSet(v) { ckSet(K_LIC, v, 400); lsSet(K_LIC, v); } function licDel() { ckDel(K_LIC); lsDel(K_LIC); } // 项目号也要跨子域可见:播放页 URL 里没有 projectId,只能靠这里带过去 function pidGet() { const c = ckGet('lcs_project'); if (c && c.pid) return c.pid; try { return localStorage.getItem('lcs_project') || ''; } catch (e) { return ''; } } function pidSet(pid) { if (!pid) return; ckSet('lcs_project', { pid: pid }, 30); try { localStorage.setItem('lcs_project', pid); } catch (e) {} } let licHost = LIC_HOSTS[0]; let engineReady = false; let licBusy = false; let licMsg = ''; let remote = {}; // 服务端下发的售卖信息(购买链接、客服) function lsGet(k) { try { return JSON.parse(localStorage.getItem(k) || 'null'); } catch (e) { return null; } } function lsSet(k, v) { try { localStorage.setItem(k, JSON.stringify(v)); return true; } catch (e) { return false; } } function lsDel(k) { try { localStorage.removeItem(k); } catch (e) {} } // 浏览器指纹:首次生成后固化,避免浏览器升级导致漂移 function deviceFp() { const memo = lsGet(K_FP); if (memo && memo.v) return memo.v; const raw = [ navigator.userAgent, navigator.language, navigator.hardwareConcurrency || 0, screen.width + 'x' + screen.height, screen.colorDepth, new Date().getTimezoneOffset(), ].join('|'); let h = 0x811c9dc5; for (let i = 0; i < raw.length; i++) { h ^= raw.charCodeAt(i); h = (h * 0x01000193) >>> 0; } const v = h.toString(16).padStart(8, '0') + '-' + raw.length.toString(16); lsSet(K_FP, { v: v }); return v; } // 学习平台账号(JWT sub)是最稳的绑定依据,读不到再用设备指纹 function readAccount() { try { const raw = localStorage.getItem('qlt_token'); if (!raw) return null; const tok = JSON.parse(raw); const at = tok && tok.access_token; if (!at) return null; let p = at.split('.')[1].replace(/-/g, '+').replace(/_/g, '/'); while (p.length % 4) p += '='; const bin = atob(p); const bytes = new Uint8Array(bin.length); for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i); const j = JSON.parse(new TextDecoder('utf-8').decode(bytes)); if (!j || !j.sub) return null; return { uid: 'u:' + j.sub, name: j.name || '' }; } catch (e) { return null; } } function licPost(path, body) { const url = licHost + path; return fetch(url, { method: 'POST', credentials: 'omit', headers: { 'content-type': 'text/plain;charset=UTF-8' }, body: JSON.stringify(body || {}), }).then(r => r.json().then(j => ({ status: r.status, body: j }))); } function licFetch(path) { const url = licHost + path; return fetch(url, { credentials: 'omit', cache: 'no-store' }) .then(r => r.json().then(j => ({ status: r.status, body: j }))); } // 逐个探测可用入口,任一成功则锁定;同时取回服务端下发的售卖信息 let lastPingAt = 0; async function pickHost(force) { if (!force && remote && remote.code === 0 && Date.now() - lastPingAt < 60000) return true; lastPingAt = Date.now(); if (licHost) { try { const r = await licFetch('/v1/ping'); if (r.status === 200) { remote = r.body || {}; lsSet('lcs_remote', remote); return true; } } catch (e) {} } for (const h of LIC_HOSTS) { try { const r = await fetch(h + '/v1/ping', { credentials: 'omit', cache: 'no-store' }) .then(x => x.json()); if (r && r.code === 0) { licHost = h; remote = r; lsSet('lcs_remote', r); return true; } } catch (e) {} } return false; } async function runEngine(code, meta) { if (engineReady) return true; try { window.__LCS_LIC__ = meta || {}; // 目标站 CSP 仅含 frame-ancestors,未限制脚本来源,可直接执行下发的业务包 (new Function(code))(); engineReady = true; licMsg = '完整引擎运行中'; return true; } catch (e) { licMsg = '引擎启动失败:' + ((e && e.message) || '未知错误'); return false; } } async function loadPkg(meta) { const cache = lsGet(K_PKG); if (cache && cache.sha && meta && cache.sha === meta.sha && cache.code) { return runEngine(cache.code, meta); } const r = await fetch(licHost + '/v1/pkg', { credentials: 'omit', cache: 'no-store', headers: { 'x-lic': (licGet() || {}).token || '' }, }); if (r.status !== 200) { licDel(); lsDel(K_PKG); licMsg = '授权已失效,请重新激活'; return false; } const code = await r.text(); if (!code || code.length < 200) { licMsg = '业务包异常,请稍后重试'; return false; } lsSet(K_PKG, { sha: (meta && meta.sha) || '', code: code, v: (meta && meta.v) || '' }); return runEngine(code, meta); } async function renewLic() { const lic = licGet(); if (!lic || !lic.token) return false; if (!(await pickHost())) { const okAt = +(lsGet(K_TRIAL) || 0); if (okAt && Date.now() - okAt < OFFLINE_GRACE) { const cache = lsGet(K_PKG); if (cache && cache.code) { licMsg = '离线宽限中'; return runEngine(cache.code, { offline: true }); } } licMsg = '授权服务器连接失败'; return false; } try { const r = await licPost('/v1/renew', { token: lic.token, fp: deviceFp() }); if (r.status !== 200) { licDel(); lsDel(K_PKG); licMsg = (r.body && r.body.msg) || '授权已失效'; return false; } lsSet(K_TRIAL, Date.now()); return loadPkg(r.body.pkg); } catch (e) { const okAt = +(lsGet(K_TRIAL) || 0); if (okAt && Date.now() - okAt < OFFLINE_GRACE) { const cache = lsGet(K_PKG); if (cache && cache.code) { licMsg = '离线宽限中'; return runEngine(cache.code, { offline: true }); } } licMsg = '授权校验失败'; return false; } } async function activate(cdk) { if (licBusy) return; licBusy = true; render(); try { const acc = readAccount(); if (!acc) { licMsg = '请先登录学习平台,再回到本页激活'; return; } if (!(await pickHost())) { licMsg = '授权服务器连接失败,请稍后重试'; return; } const r = await licPost('/v1/activate', { cdk: cdk, uid: acc.uid, name: acc.name, fp: deviceFp(), }); if (r.status !== 200) { licMsg = (r.body && r.body.msg) || '激活失败'; return; } licSet({ token: r.body.token, exp: r.body.exp, at: Date.now() }); lsSet(K_TRIAL, Date.now()); licMsg = '激活成功,正在装载引擎'; render(); const ok = await loadPkg(r.body.pkg); // 状态已写进 .qlteacher.com 的 cookie,通知同源的其他标签页立刻跟上 broadcast(); if (ok) await hopToWorkbench(); } catch (e) { licMsg = '网络异常,请检查网络后重试'; } finally { licBusy = false; render(); } } // ---- 跨页面同步:同源标签用 BroadcastChannel 秒级通知,跨子域靠 cookie 轮询 let syncChan = null; try { syncChan = new BroadcastChannel('lcs_lic'); } catch (e) {} let syncAt = 0; function broadcast() { try { syncChan && syncChan.postMessage({ t: 'lic', at: Date.now() }); } catch (e) {} try { lsSet(K_SYNC, Date.now()); } catch (e) {} // 兜底触发 storage 事件 } // 发现别处已经完成激活、本页还没装载引擎,就静默补上 async function pullIfActivated() { if (engineReady || licBusy) return; const lic = licGet(); if (!lic || !lic.token) return; if (Date.now() - syncAt < 3000) return; syncAt = Date.now(); licMsg = '检测到其他窗口已激活,正在同步'; render(); await renewLic(); render(); } // ---- 激活后从播放页回到工作台:播放页只能看到当前这门课,跑完全部课程必须回项目首页 const WORKBENCH = 'https://yxjc.qlteacher.com'; // 播放页 URL 里没有项目号,依次从共享 cookie、来源页取,最后用最常见的项目兜底 function pidGuess() { const known = pidGet(); if (known) return known; try { const m = (document.referrer || '').match(/\/(?:pre-)?project\/([A-Za-z0-9]+)/); if (m && m[1] && m[1] !== 'project') return m[1]; } catch (e) {} return ''; } function workbenchUrl() { // 猜错也不要紧:平台会把无权限的项目纠正掉,引擎进入后还会再探一次真实项目 return WORKBENCH + '/project/' + (pidGuess() || 'xx2026') + '/index'; } async function hopToWorkbench() { if (location.hostname !== 'player.qlteacher.com') return false; if (sessionStorage.getItem('lcs_worked')) return false; sessionStorage.setItem('lcs_worked', '1'); licMsg = '正在跳转到工作台,将处理全部课程'; render(); await new Promise(r => setTimeout(r, 1600)); location.href = workbenchUrl(); return true; } // ================================================================== // 免费功能:后台续播与倍速观察 // ================================================================== const projectPage = location.hostname === 'yxjc.qlteacher.com' && /^\/(?:pre-)?project\/(?:yey|xx|cz|gz)20\d{2}(?:\/|$)/.test(location.pathname); const playerPage = location.hostname === 'player.qlteacher.com' && /^\/learning(?:\/|$)/.test(location.pathname); if (!projectPage && !playerPage) return; if (document.getElementById('qlteacher-playback-helper')) return; // 在项目页把当前项目号记进 .qlteacher.com 的 cookie: // 播放页的 URL 里没有 projectId,只有靠它才知道该跳回哪个工作台。 if (projectPage) { const pm = location.pathname.match(/\/(?:pre-)?project\/([A-Za-z0-9]+)/); if (pm && pm[1] && pm[1] !== 'project') pidSet(pm[1]); } const RATES = [1,1.25,1.5,2,3,4,8,16]; const PROBE_RATES = [2,3,4,8,16]; const states = new WeakMap(); let speedMode='follow'; let requestedRate=1; let speedNote=''; let probe=null; let validationBlocked = false; let scheduled = false; let busy = false; let message = '等待课程加载'; let backgroundStarted = null; let backgroundStartTime = null; let backgroundVideo = null; let backgroundSource = null; let backgroundSeeked = false; let backgroundResult = ''; const panel = document.createElement('div'); panel.id = 'qlteacher-playback-helper'; panel.style.cssText = 'position:fixed;right:16px;bottom:18px;z-index:2147483646;transition:bottom .3s ease;'; const root = panel.attachShadow({mode:'open'}); root.innerHTML = `
📚2026 课程播放助手

完整引擎:未激活
购买卡密
`; (document.body || document.documentElement).appendChild(panel); const status = root.getElementById('status'); const clock = root.getElementById('time'); const background = root.getElementById('background'); const speed = root.getElementById('speed'); const modeSelect = root.getElementById('mode'); const rateSelect = root.getElementById('rate'); const probeButton = root.getElementById('probe'); const licState = root.getElementById('licstate'); const licBox = root.getElementById('licbox'); const cdkInput = root.getElementById('cdk'); const actButton = root.getElementById('act'); const buyLink = root.getElementById('buy'); modeSelect.value=speedMode; rateSelect.value=String(requestedRate); const collapseBtn = root.getElementById('collapse'); const panelBody = root.getElementById('pbody'); let panelCollapsed = false; collapseBtn.addEventListener('click', () => { panelCollapsed = !panelCollapsed; panelBody.classList.toggle('hide', panelCollapsed); collapseBtn.textContent = panelCollapsed ? '▸' : '▾'; }); function applyRate(video, rate) { if (validationBlocked && rate !== 1) return false; const state=states.get(video); if (!state) return false; state.expectedRate=rate; try { video.playbackRate=rate; if (Math.abs(video.playbackRate-rate)>0.05) throw Error('Rate rejected'); state.appliedSource=video.currentSrc || video.src; return true; } catch (error) { state.expectedRate=null; state.appliedSource=video.currentSrc || video.src; speedNote='播放器不支持 '+rate+'×,请降低倍速'; return false; } } function stopProbe(note) { if (!probe) return; const run=probe; probe=null; speedMode='fixed'; requestedRate=run.best; modeSelect.value=speedMode; rateSelect.value=String(requestedRate); applyRate(run.video,requestedRate); speedNote=note+';采用 '+requestedRate+'×'; } function startProbe() { if (validationBlocked || validationWarning()) { tick(); return; } const video=currentVideo(); if (!video || video.paused || video.ended || questionOpen()) { speedNote='请先播放视频,再开始试速'; render(); return; } stopProbe('重新试速'); speedMode='auto'; modeSelect.value=speedMode; probe={video,source:video.currentSrc || video.src,index:0,best:1,sample:null}; if (!applyRate(video,PROBE_RATES[0])) stopProbe('首档倍速不可用'); else speedNote='试速 '+PROBE_RATES[0]+'×,每档观察至少 6 秒'; render(); } function observeSpeed(video,state) { const now=Date.now(); if (video.paused || video.ended || video.seeking || questionOpen()) { state.sample=null; if (probe) stopProbe('播放中断,试速结束'); return; } if (probe) { const run=probe; if (run.video !== video || run.source !== (video.currentSrc || video.src)) { stopProbe('视频已切换,试速结束'); return; } if (!run.sample) run.sample={at:now,time:video.currentTime}; const elapsed=(now-run.sample.at)/1000; if (elapsed<6) return; const observed=(video.currentTime-run.sample.time)/elapsed; const target=PROBE_RATES[run.index]; state.measured=observed; if (elapsed>15 || !Number.isFinite(observed) || observedtarget*1.3) { stopProbe(elapsed>15 ? '采样间隔过长,请在前台重新试速' : '当前档进度不稳定,结束试速'); return; } run.best=target; run.index++; if (run.index>=PROBE_RATES.length) { stopProbe('试速完成'); return; } run.sample=null; const next=PROBE_RATES[run.index]; if (!applyRate(video,next)) stopProbe('更高倍速不可用'); else speedNote='实测 '+observed.toFixed(2)+'×;正在试 '+next+'×'; return; } if (!state.sample) { state.sample={at:now,time:video.currentTime}; return; } const elapsed=(now-state.sample.at)/1000; if (elapsed<4) return; const observed=(video.currentTime-state.sample.time)/elapsed; state.measured=elapsed<=15 && observed>=0 ? observed : null; state.sample={at:now,time:video.currentTime}; } function visible(el) { if (!el || !el.isConnected || el.hidden) return false; const style = getComputedStyle(el); return style.display !== 'none' && style.visibility !== 'hidden' && el.getClientRects().length > 0; } function currentVideo() { const videos = [...document.querySelectorAll('video')].filter(visible); return videos.find(v => !v.paused && !v.ended) || videos[0] || null; } function questionOpen() { const title = document.querySelector('.segmented-text-ellipsis'); if (title && visible(title) && title.textContent.trim() === '测试题') return true; return [...document.querySelectorAll('[role="dialog"], .ant-modal-content')].some(el => visible(el) && (el.querySelector('input[type="radio"], input[type="checkbox"], .ant-radio-input, .ant-checkbox') || /测试题|请作答|请回答|单选题|多选题|提交答案/.test(el.textContent))); } function validationWarning() { const text=document.body?.innerText || ''; return /(?:进度[\s\S]{0,40}(?:时长|时间)|(?:时长|时间)[\s\S]{0,40}进度)[\s\S]{0,30}(?:不符|不一致|异常)|(?:学习进度|学习时长|学习时间|学习速度)[\s\S]{0,20}异常[\s\S]{0,40}刷新/.test(text); } function stopForValidation(video) { validationBlocked=true; probe=null; speedMode='follow'; requestedRate=1; modeSelect.value=speedMode; rateSelect.value='1'; speedNote='平台要求刷新;本页倍速控制已停止'; message='进度与学习时间校验未通过,请刷新播放器'; if (video) { applyRate(video,1); video.pause(); message='进度与学习时间校验未通过,请刷新播放器'; } } function formatTime(seconds) { if (!Number.isFinite(seconds)) return '--:--'; return Math.floor(seconds / 60) + ':' + String(Math.floor(seconds % 60)).padStart(2,'0'); } function render() { status.textContent = message; status.dataset.s = validationBlocked ? 'err' : ''; const video = currentVideo(); clock.textContent = video ? formatTime(video.currentTime) + ' / ' + formatTime(video.duration) : ''; background.textContent = backgroundResult; const measured=video && states.get(video)?.measured; speed.textContent=(video ? '当前 '+video.playbackRate+'×' : '目标 '+requestedRate+'×')+ (Number.isFinite(measured) ? ',实测 '+measured.toFixed(2)+'×' : '')+ (speedNote ? ';'+speedNote : ''); rateSelect.disabled=validationBlocked || speedMode !== 'fixed'; modeSelect.disabled=validationBlocked; probeButton.disabled=validationBlocked; probeButton.textContent=probe ? '结束试速' : '开始试速'; renderLic(); } function buyUrl() { if (remote && remote.buy) return remote.buy; const cached = lsGet('lcs_remote'); return (cached && cached.buy) || ''; } function renderLic() { if (!licState) return; const lic = licGet(); let text, cls = ''; if (engineReady) { const exp = lic && lic.exp ? new Date(lic.exp * 1000) : null; text = '完整引擎运行中' + (exp ? ' · 至 ' + exp.toLocaleDateString('zh-CN') : ''); cls = 'on'; licBox.style.display = 'none'; // 完整引擎自带的界面占右下角,本面板上移避让 panel.style.bottom = '296px'; } else if (licBusy) { text = licMsg || '正在校验授权'; } else if (lic && lic.token) { text = licMsg || '授权校验中'; } else { text = '完整引擎:未激活'; } if (licMsg && /失败|异常|错误|失效|过期|不存在|作废|绑定|未读取/.test(licMsg)) cls = 'err'; licState.textContent = text; licState.className = cls; actButton.disabled = licBusy; cdkInput.disabled = licBusy; const b = buyUrl(); buyLink.href = b || '#'; buyLink.textContent = b ? '购买卡密' : '获取购买地址'; buyLink.className = b ? '' : ''; buyLink.onclick = e => { if (b) return; e.preventDefault(); const c = (remote && remote.contact) || (lsGet('lcs_remote') || {}).contact || ''; licMsg = c ? '请联系卖家购买:' + c : '请向卖家索取购买地址'; render(); }; } function stateFor(video) { let state = states.get(video); if (state) return state; state = {source:video.currentSrc || video.src, expectedRate:null,appliedSource:null,sample:null,measured:null}; states.set(video,state); video.addEventListener('ratechange', () => { state.sample=null; state.measured=null; if (state.expectedRate !== null && Math.abs(video.playbackRate-state.expectedRate)>0.05) { // 尊重播放器的限制,停止试速并跟随实际速度。 probe=null; speedMode='follow'; modeSelect.value=speedMode; speedNote='播放器调整了倍速,已改为跟随播放器'; state.expectedRate=null; } render(); }); video.addEventListener('seeking', () => { state.sample=null; state.measured=null; if (document.hidden) backgroundSeeked=true; if (probe) stopProbe('进度发生跳转,试速结束'); }); video.addEventListener('playing', () => { state.sample=null; message = document.hidden ? '正在后台播放' : '正在播放'; render(); }); video.addEventListener('pause', () => { if (video.ended) return; message = questionOpen() ? '等待本人处理测验' : '已暂停,点击视频继续'; queue(); }); video.addEventListener('ended', () => { message='本段视频播放结束'; render(); }); video.addEventListener('timeupdate', render); video.addEventListener('loadedmetadata', queue); video.addEventListener('emptied', queue); return state; } function tick() { if (busy) return; busy=true; try { const video=currentVideo(); if (validationBlocked) { message='进度与学习时间校验未通过,请刷新播放器'; return; } if (validationWarning()) { stopForValidation(video); return; } if (questionOpen()) { if(probe)stopProbe('遇到测验,试速结束'); message='等待本人处理测验'; return; } if (!video) { message='请在页面上点开课程视频'; return; } const state=stateFor(video); const source=video.currentSrc || video.src; if (source !== state.source) { state.source=source; state.sample=null; state.measured=null; } if (speedMode === 'fixed' && state.appliedSource !== source) applyRate(video,requestedRate); if (!engineReady) observeSpeed(video,state); if (video.error) { message='视频加载出错,请检查网络或课程资源'; return; } // 只观察,不代劳:播放/暂停由使用者自己操作 if (!video.paused && !video.ended) { message=engineReady ? '完整引擎运行中' : (document.hidden ? '正在后台播放' : '正在播放'); } else if (video.ended) { message='本段视频播放结束'; } else { message='已暂停,点击视频继续'; } } catch (error) { message='页面暂未就绪,稍后重试'; console.warn('[QL2026]',error); } finally { busy=false; render(); } } function queue() { if (scheduled) return; scheduled=true; setTimeout(() => { scheduled=false; tick(); },300); } modeSelect.addEventListener('change', () => { if (validationBlocked || validationWarning()) { tick(); return; } const selected=modeSelect.value; if (probe) stopProbe('已切换方式'); speedMode=selected; modeSelect.value=selected; speedNote=selected === 'auto' ? '仅比较播放速度,学时以平台记录为准;点击开始试速' : ''; const video=currentVideo(); if (video && selected === 'fixed') applyRate(video,requestedRate); if (video && selected === 'follow') stateFor(video).expectedRate=null; render(); }); rateSelect.addEventListener('change', () => { if (validationBlocked || validationWarning()) { tick(); return; } const selected=Number(rateSelect.value); if (!RATES.includes(selected)) return; if (probe) stopProbe('已选择固定倍速'); speedMode='fixed'; modeSelect.value=speedMode; requestedRate=selected; speedNote=''; const video=currentVideo(); if (video) applyRate(video,requestedRate); render(); }); probeButton.addEventListener('click', () => { if (validationBlocked || validationWarning()) { tick(); return; } if (probe) stopProbe('手动结束试速'); else startProbe(); render(); }); actButton.addEventListener('click', () => { const code = (cdkInput.value || '').trim(); if (!/^[A-Za-z0-9]{8,32}$/.test(code)) { licMsg = '卡密格式不正确'; render(); return; } activate(code); }); cdkInput.addEventListener('keydown', e => { if (e.key === 'Enter') actButton.click(); }); document.addEventListener('visibilitychange', () => { const video=currentVideo(); if (document.hidden) { backgroundStarted=Date.now(); backgroundStartTime=video ? video.currentTime : null; backgroundVideo=video; backgroundSource=video ? (video.currentSrc || video.src) : null; backgroundSeeked=false; if (video) stateFor(video).retries=0; backgroundResult='后台观察中'; } else if (backgroundStarted !== null) { const elapsed=(Date.now()-backgroundStarted)/1000; const sameVideo=video && video === backgroundVideo && (video.currentSrc || video.src) === backgroundSource; const advanced=sameVideo && !backgroundSeeked && backgroundStartTime !== null ? video.currentTime-backgroundStartTime : NaN; backgroundResult=Number.isFinite(advanced) ? '上次后台 '+Math.round(elapsed)+' 秒,视频前进 '+Math.max(0,Math.round(advanced))+' 秒'+ (elapsed>0 ? '('+(Math.max(0,advanced)/elapsed).toFixed(2)+'×)' : '') : '后台期间视频已切换、跳转或当前页没有视频,请重新测试'; backgroundStarted=null; backgroundStartTime=null; backgroundVideo=null; backgroundSource=null; } // 不刷新、不伪造页面可见性;让真实媒体继续播放。 queue(); render(); }); const observer=new MutationObserver(queue); observer.observe(document.body || document.documentElement,{childList:true,subtree:true}); const timer=setInterval(tick,2000); window.addEventListener('pagehide', () => { observer.disconnect(); clearInterval(timer); },{once:true}); tick(); // 授权自检:已激活则静默续期并装载引擎,期间免费功能照常 if (projectPage || playerPage) { remote = lsGet('lcs_remote') || {}; render(); setTimeout(async () => { // 未激活用户也要拉一次售卖信息,否则面板上的购买入口拿不到卡网地址 try { await pickHost(); } catch (e) {} render(); try { await renewLic(); } catch (e) {} render(); // 本页装载完引擎且人在播放页,同样应该回工作台跑全部课程 if (engineReady) await hopToWorkbench(); }, 1200); setInterval(() => { if (engineReady && !licBusy) void renewLic(); }, 30 * 60 * 1000); // 未激活时定期同步售卖信息,保证购买入口始终可用 setInterval(() => { if (!engineReady && !licBusy) void pickHost(true).then(render); }, 6 * 3600 * 1000); // 同源标签页瞬时同步 if (syncChan) { syncChan.onmessage = () => { void pullIfActivated(); }; } window.addEventListener('storage', e => { if (e.key === K_SYNC || e.key === K_LIC) void pullIfActivated(); }); // 跨子域只能轮询 cookie:工作台激活后,已经开着的播放页在 5 秒内自动跟上 setInterval(() => { void pullIfActivated(); }, 5000); } })();