// ==UserScript== // @name |🥇PP网课小助手|飘飘|热更新版本|超星学习通·知到智慧树·雨课堂| // @namespace 飘飘 // @version 2.5.3 // @author PIAOPIAO // @license MIT // @description (´-ω-`)《题库免费、AI 双校验,这合理吗?》|超星学习通·知到智慧树·雨课堂|Claude/ChatGPT/Gemini/DeepSeek等N款AI都支持哦|视频自动播放倍速+章节任务+作业考试全题型自动答题|手机平板可用| // @icon https://cdn.jsdmirror.com/gh/piaopiaosir/pp-course-assistant@main/newicon.png // @match *://*.chaoxing.com/* // @match *://*.xuexitong.com/* // @match *://*.xueyinonline.com/* // @match *://*.edu.cn/* // @match *://*.nbdlib.cn/* // @match *://*.hnsyu.net/* // @match *://*.gdhkmooc.com/* // @match *://*.sslibrary.com/* // @match *://onlineexamh5new.zhihuishu.com/* // @match *://*.zhihuishu.com/* // @match *://*.polymas.com/* // @match *://*.yuketang.cn/* // @match *://*.gdufemooc.cn/* // @match *://*.xhz123.icu/* // @require https://lib.baomitu.com/vue/3.5.0/vue.global.prod.js // @require https://lib.baomitu.com/vue-demi/0.14.7/index.iife.js // @require data:application/javascript,window.Vue%3DVue%3B // @require https://lib.baomitu.com/element-plus/2.8.2/index.full.min.js // @require https://lib.baomitu.com/pinia/2.3.1/pinia.iife.min.js // @require https://lib.baomitu.com/rxjs/7.8.2/rxjs.umd.min.js // @require https://lib.baomitu.com/blueimp-md5/2.19.0/js/md5.min.js // @resource ElementPlusStyle https://lib.baomitu.com/element-plus/2.8.2/index.min.css // @resource fontDecryptLib https://cdn.jsdmirror.com/gh/piaopiaosir/pp-font-decrypt@v1.2.0/font-decrypt.js // @resource fontDecryptLibGh https://gh-proxy.com/https://raw.githubusercontent.com/piaopiaosir/pp-font-decrypt/v1.2.0/font-decrypt.js // @connect * // @connect 122.152.249.109 // @connect 152.136.30.238 // @connect gh-proxy.com // @connect scriptcat.org // @connect cdn.jsdmirror.com // @connect raw.githubusercontent.com // @grant GM_addStyle // @grant GM_getResourceText // @grant GM_getTab // @grant GM_saveTab // @grant GM_getValue // @grant GM_setValue // @grant GM_xmlhttpRequest // @grant unsafeWindow // @run-at document-start // @tag 超星学习通 // @tag 知到智慧树 // @tag 雨课堂 // @tag 网课自动答题 // @tag 免费题库 // @tag 全题型支持 // @tag AI多模型 // @tag 热更新 // ==/UserScript== (function () { 'use strict'; const W = (typeof unsafeWindow !== 'undefined' && unsafeWindow) || window; const IS_TOP = (() => { try { return window.self === window.top; } catch (e) { return true; } })(); const CONFIG = { VERSION_SERVER: { VERSION_URL: 'https://scriptcat.org/scripts/code/5597/%7C%F0%9F%A5%87PP%E7%BD%91%E8%AF%BE%E5%B0%8F%E5%8A%A9%E6%89%8B%7C%E9%A3%98%E9%A3%98%7C.meta.js', BOOTSTRAP_VERSION_URL: 'https://scriptcat.org/scripts/code/5615/%7C%F0%9F%A5%87PP%E7%BD%91%E8%AF%BE%E5%B0%8F%E5%8A%A9%E6%89%8B%7C%E9%A3%98%E9%A3%98%7C%E7%83%AD%E6%9B%B4%E6%96%B0%E7%89%88%E6%9C%AC%7C.meta.js', BOOTSTRAP_UPDATE_URL: 'https://scriptcat.org/scripts/code/5615/%7C%F0%9F%A5%87PP%E7%BD%91%E8%AF%BE%E5%B0%8F%E5%8A%A9%E6%89%8B%7C%E9%A3%98%E9%A3%98%7C%E7%83%AD%E6%9B%B4%E6%96%B0%E7%89%88%E6%9C%AC%7C.user.js' }, SCRIPTCAT: { SCRIPT_ID: '5597', SCRIPT_NAME: 'PP网课小助手', CODE_URL: 'https://scriptcat.org/scripts/code/5597/%7C%F0%9F%A5%87PP%E7%BD%91%E8%AF%BE%E5%B0%8F%E5%8A%A9%E6%89%8B%7C%E9%A3%98%E9%A3%98%7C.user.js' }, SOURCE: { GH_PROXY_URL: 'https://gh-proxy.com/https://raw.githubusercontent.com/piaopiaosir/pp-course-assistant/main/script.user.js', CDN_URL: 'https://cdn.jsdmirror.com/gh/piaopiaosir/pp-course-assistant@main/script.user.js', BOOTSTRAP_GH_PROXY_URL: 'https://gh-proxy.com/https://raw.githubusercontent.com/piaopiaosir/pp-course-assistant-hot-update/main/script-hot-update.user.js', BOOTSTRAP_CDN_URL: 'https://cdn.jsdmirror.com/gh/piaopiaosir/pp-course-assistant-hot-update@main/script-hot-update.user.js' }, CACHE_KEY: 'cloud_script_cache', VERSION_KEY: 'cloud_script_version', LAST_CHECK_KEY: 'last_check_time', RELOAD_FLAG_KEY: '__pp_hot_boot_reload__' }; const log = { info: (msg, ...args) => console.log(`%c[云端脚本] ${msg}`, 'color: #667eea; font-weight: bold;', ...args), success: (msg, ...args) => console.log(`%c[云端脚本] ✓ ${msg}`, 'color: #10b981; font-weight: bold;', ...args), warn: (msg, ...args) => console.warn(`%c[云端脚本] ⚠ ${msg}`, 'color: #f59e0b; font-weight: bold;', ...args), error: (msg, ...args) => console.error(`%c[云端脚本] ✗ ${msg}`, 'color: #ef4444; font-weight: bold;', ...args) }; const gmGet = (key, fallback) => { try { return typeof GM_getValue === 'function' ? GM_getValue(key, fallback) : fallback; } catch (e) { return fallback; } }; const gmSet = (key, value) => { try { if (typeof GM_setValue === 'function') GM_setValue(key, value); } catch (e) {} }; function compareVersion(v1, v2) { const parts1 = String(v1 || '0').split('.').map(Number); const parts2 = String(v2 || '0').split('.').map(Number); for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) { const p1 = parts1[i] || 0; const p2 = parts2[i] || 0; if (p1 > p2) return 1; if (p1 < p2) return -1; } return 0; } function httpGet(url, isText = false, headers = {}, timeout = 15000) { return new Promise((resolve, reject) => { GM_xmlhttpRequest({ method: 'GET', url: url, headers: headers, timeout: timeout, onload: (response) => { if (response.status === 200) { resolve(isText ? response.responseText : response.response); } else { reject(new Error(`HTTP ${response.status}`)); } }, onerror: () => reject(new Error('网络请求失败')), ontimeout: () => reject(new Error('请求超时')) }); }); } const VERSION_RE = /\/\/\s*@version\s+(\d+\.\d+\.\d+)/; const VERSION_PREFIX_BYTES = 64 * 1024; async function fetchVersionText(url, timeout, maxBytes) { const controller = typeof AbortController === 'function' ? new AbortController() : null; const timer = controller ? setTimeout(() => controller.abort(), timeout) : null; try { const response = await fetch(url, { method: 'GET', cache: 'no-store', ...(controller ? { signal: controller.signal } : {}) }); if (response.status !== 200 && response.status !== 206) { throw new Error(`HTTP ${response.status}`); } const reader = response.body && typeof response.body.getReader === 'function' ? response.body.getReader() : null; if (!reader || typeof TextDecoder !== 'function') { return await response.text(); } const limit = maxBytes || VERSION_PREFIX_BYTES; const decoder = new TextDecoder(); let text = ''; let bytes = 0; try { while (bytes < limit) { const chunk = await reader.read(); if (!chunk || chunk.done) break; bytes += chunk.value ? chunk.value.length : 0; text += decoder.decode(chunk.value, { stream: true }); if (VERSION_RE.test(text)) break; } } finally { try { await reader.cancel(); } catch (e) {} } return text; } finally { if (timer) clearTimeout(timer); } } function getLocalCache() { return { version: gmGet(CONFIG.VERSION_KEY, ''), code: gmGet(CONFIG.CACHE_KEY, ''), lastCheck: gmGet(CONFIG.LAST_CHECK_KEY, 0) }; } function saveLocalCache(version, code) { gmSet(CONFIG.VERSION_KEY, version); gmSet(CONFIG.CACHE_KEY, code); gmSet(CONFIG.LAST_CHECK_KEY, Date.now()); } function isValidScriptCode(code) { return typeof code === 'string' && code.indexOf('// ==/UserScript==') !== -1 && /\/\/\s*@version\s+\d+\.\d+\.\d+/.test(code); } function scriptVersionOf(code) { const matched = String(code || '').match(/\/\/\s*@version\s+(\d+\.\d+\.\d+)/); return matched ? matched[1] : 'unknown'; } async function fetchVersionFromSources(sources) { for (const source of sources) { try { log.info(`从${source.name}获取版本信息...`); let text; if (source.prefix && typeof fetch === 'function') { text = await fetchVersionText(source.url, source.timeout); } else { const url = source.url + (source.url.includes('?') ? '&' : '?') + 't=' + Date.now(); text = await httpGet(url, true, { 'Cache-Control': 'no-cache', 'Pragma': 'no-cache' }, source.timeout); } const versionMatch = String(text || '').match(/\/\/\s*@version\s+(\d+\.\d+\.\d+)/); if (versionMatch && versionMatch[1]) { log.success(`${source.name}最新版本: ${versionMatch[1]}`); return { version: versionMatch[1], updateUrl: source.updateUrl || source.url }; } throw new Error('响应中没有 @version'); } catch (e) { log.warn(`${source.name}获取版本失败:`, e.message); } } throw new Error('所有版本源均失败'); } async function downloadScriptCode() { const headers = { 'Cache-Control': 'no-cache', 'Pragma': 'no-cache' }; const sources = [ { name: 'gh-proxy', url: CONFIG.SOURCE.GH_PROXY_URL }, { name: '脚本猫', url: CONFIG.SCRIPTCAT.CODE_URL }, { name: 'CDN', url: CONFIG.SOURCE.CDN_URL } ]; let lastError = null; for (const source of sources) { try { log.info(`从${source.name}下载脚本代码...`); const url = source.url + (source.url.includes('?') ? '&' : '?') + 't=' + Date.now(); const code = await httpGet(url, true, headers, 30000); if (!isValidScriptCode(code)) { throw new Error('返回内容不是有效的用户脚本代码'); } const version = scriptVersionOf(code); log.success(`${source.name}下载完成,版本: ${version}`); return { code, version, source: source.url }; } catch (e) { lastError = e; log.warn(`${source.name}下载失败:`, e.message); } } log.error('全部下载链接均失败:', lastError && lastError.message); throw lastError || new Error('脚本下载失败'); } async function fetchLatestVersion() { return fetchVersionFromSources([ { name: 'gh-proxy', url: CONFIG.SOURCE.GH_PROXY_URL, updateUrl: CONFIG.SOURCE.GH_PROXY_URL, prefix: true, timeout: 20000 }, { name: '脚本猫 meta', url: CONFIG.VERSION_SERVER.VERSION_URL, updateUrl: CONFIG.SCRIPTCAT.CODE_URL, timeout: 30000 }, { name: 'CDN', url: CONFIG.SOURCE.CDN_URL, updateUrl: CONFIG.SOURCE.CDN_URL, timeout: 20000 } ]); } function capturePageNatives() { let origin = null; try { origin = W.originFunction; } catch (e) { origin = null; } if (!origin || typeof origin !== 'object') return null; const snap = { origin, originDescriptor: undefined, originAttachDescriptor: undefined, getSelectionOwnDescriptor: undefined, getSelectionValue: undefined, attachShadowValue: undefined, xhrSendValue: undefined, fetchValue: undefined, fnCallValue: undefined }; try { snap.originDescriptor = Object.getOwnPropertyDescriptor(W, 'originFunction'); } catch (e) {} try { snap.originAttachDescriptor = Object.getOwnPropertyDescriptor(origin, 'AttachShadow'); } catch (e) {} try { snap.getSelectionOwnDescriptor = Object.getOwnPropertyDescriptor(document, 'getSelection'); } catch (e) {} try { snap.getSelectionValue = document.getSelection; } catch (e) {} try { snap.attachShadowValue = W.Element.prototype.attachShadow; } catch (e) {} try { snap.xhrSendValue = W.XMLHttpRequest.prototype.send; } catch (e) {} try { snap.fetchValue = W.fetch; } catch (e) {} try { snap.fnCallValue = W.Function.prototype.call; } catch (e) {} return function restorePageNatives() { try { if (snap.originAttachDescriptor) { Object.defineProperty(origin, 'AttachShadow', snap.originAttachDescriptor); } } catch (e) {} try { if (snap.originDescriptor) { Object.defineProperty(W, 'originFunction', snap.originDescriptor); } else { delete W.originFunction; } } catch (e) {} try { if (snap.attachShadowValue && W.Element.prototype.attachShadow !== snap.attachShadowValue) { W.Element.prototype.attachShadow = snap.attachShadowValue; } } catch (e) {} try { if (snap.xhrSendValue && W.XMLHttpRequest.prototype.send !== snap.xhrSendValue) { W.XMLHttpRequest.prototype.send = snap.xhrSendValue; } } catch (e) {} try { if (snap.fetchValue && W.fetch !== snap.fetchValue) { W.fetch = snap.fetchValue; } } catch (e) {} try { if (snap.fnCallValue && W.Function.prototype.call !== snap.fnCallValue) { W.Function.prototype.call = snap.fnCallValue; } } catch (e) {} try { if (snap.getSelectionOwnDescriptor) { Object.defineProperty(document, 'getSelection', snap.getSelectionOwnDescriptor); } else { let removed = false; try { removed = delete document.getSelection; } catch (e) {} if (!removed && snap.getSelectionValue) { document.getSelection = snap.getSelectionValue; } } } catch (e) {} log.info('已还原页面原生函数引用(异步执行兜底)'); }; } function enterMinimalTouchMode() { try { W.__ppZhsBridge = true; } catch (e) {} try { window.__ppZhsBridge = true; } catch (e) {} try { if (document.documentElement && !document.documentElement.hasAttribute('data-pp-zhs-bridge')) { document.documentElement.setAttribute('data-pp-zhs-bridge', '1'); } } catch (e) {} try { W.__ppZhPaperProbe = true; } catch (e) {} try { document.__ppSelectionUnlocked = true; } catch (e) {} ['setTimeout', 'setInterval'].forEach((name) => { try { const native = W[name]; if (typeof native !== 'function') return; if (Object.getOwnPropertyDescriptor(W, name) && Object.getOwnPropertyDescriptor(W, name).get) return; Object.defineProperty(W, name, { configurable: true, enumerable: true, get() { return native; }, set() {} }); } catch (e) {} }); log.warn('已启用最小接触模式:不包装页面可见原生函数'); } function installDetectionFallback() { if (!isZhsExamPage()) return; if (W.__ppDetectionFallback) return; try { W.__ppDetectionFallback = true; } catch (e) { return; } const DETECT_TEXT = '检测到异常脚本'; let neutralized = false; let disposed = false; const neutralise = () => { if (neutralized) return; neutralized = true; try { const nativeClose = W.close; W.close = function () { log.warn('已拦截页面 window.close()'); }; setTimeout(() => { try { W.close = nativeClose; } catch (e) {} }, 30000); } catch (e) {} try { document.querySelectorAll('div,dialog,section').forEach((node) => { const text = node.textContent || ''; if (text.indexOf(DETECT_TEXT) >= 0 && text.length < 400 && node.parentNode) { node.parentNode.removeChild(node); } }); } catch (e) {} }; const probe = () => { if (disposed || neutralized) return; try { const body = document.body; if (!body) return; if ((body.textContent || '').indexOf(DETECT_TEXT) >= 0) neutralise(); } catch (e) {} }; const timer = setInterval(probe, 500); setTimeout(() => { disposed = true; clearInterval(timer); }, 30000); } function isZhsExamPage() { try { const host = String((W.location && W.location.hostname) || '').toLowerCase(); if (!/(^|\.)zhihuishu\.com$/.test(host)) return false; let origin = null; try { origin = W.originFunction; } catch (e) {} if (origin && typeof origin === 'object') return true; const href = String((W.location && W.location.href) || ''); return /onlineexam|examh5|reversionteststart|dohomework|dowork|dotest|answerquestion|\/exam/i.test(href); } catch (e) { return false; } } let evalAttempted = false; function executeCode(code, version, options) { const guarded = !!(options && options.guarded); try { log.info(`执行脚本代码...(v${version || 'unknown'},${guarded ? '异步·最小接触' : 'document-start 同步'})`); window.__CLOUD_SCRIPT_LOADED__ = true; try { W.__CLOUD_SCRIPT_LOADED__ = true; } catch (e) {} window.__CLOUD_SCRIPT_VERSION__ = version || ''; try { W.__CLOUD_SCRIPT_VERSION__ = version || ''; } catch (e) {} const codeStart = code.indexOf('// ==/UserScript=='); let executableCode = code; if (codeStart !== -1) { executableCode = code.substring(codeStart + '// ==/UserScript=='.length); } executableCode = executableCode.trim(); if (typeof Vue === 'undefined') { throw new Error('Vue 未加载,请检查 @require 配置'); } log.info('依赖库检查: Vue=' + (typeof Vue !== 'undefined') + ', Pinia=' + (typeof Pinia !== 'undefined') + ', RxJS=' + (typeof rxjs !== 'undefined') + ', MD5=' + (typeof md5 !== 'undefined') + ', ElementPlus=' + (typeof ElementPlus !== 'undefined') + (typeof ElementPlus !== 'undefined' && ElementPlus.version ? '(' + ElementPlus.version + ')' : '')); let restorePageNatives = null; if (guarded) { enterMinimalTouchMode(); restorePageNatives = capturePageNatives(); } evalAttempted = true; try { eval(executableCode); } finally { if (restorePageNatives) restorePageNatives(); } log.success('脚本执行成功'); try { installDetectionFallback(); } catch (e) {} try { setupMainWindowObserver(); } catch (e) {} return true; } catch (e) { log.error('脚本执行失败:', e && e.message); hideLoadingWindow(); throw e; } } function setupMainWindowObserver() { const closeAfterInit = () => { setTimeout(() => { log.info('脚本初始化完成,关闭加载窗口'); hideLoadingWindow(); }, 500); }; if (document.readyState === 'complete') { closeAfterInit(); } else { window.addEventListener('load', closeAfterInit); } } let loadingWindow = null; function showLoadingWindow() { if (loadingWindow) return; const createLoading = () => { if (loadingWindow) return; loadingWindow = document.createElement('div'); loadingWindow.id = 'cloud-script-loading-window'; loadingWindow.innerHTML = `
脚本加载中...
`; loadingWindow.style.cssText = ` position: fixed; top: 20px; right: 20px; z-index: 2147483647; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; animation: toastSlideIn 0.3s ease; `; const style = document.createElement('style'); style.id = 'cloud-script-loading-styles'; style.textContent = ` #cloud-script-loading-window .loading-content { background: #ffffff; border: 1px solid #e5e7eb; border-left: 3px solid #0052D9; padding: 10px 16px; border-radius: 6px; display: flex; align-items: center; gap: 10px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1), 0 1px 4px rgba(0, 0, 0, 0.06); min-width: 180px; } #cloud-script-loading-window .loading-spinner { width: 18px; height: 18px; border: 2px solid #e5e7eb; border-top-color: #0052D9; border-right-color: #0052D9; border-radius: 50%; animation: loadingSpin 0.8s linear infinite; flex-shrink: 0; display: block; } #cloud-script-loading-window .loading-text { color: #374151; font-size: 13px; font-weight: 500; white-space: nowrap; } @keyframes loadingSpin { to { transform: rotate(360deg); } } @keyframes toastSlideIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } } `; (document.head || document.documentElement).appendChild(style); document.body.appendChild(loadingWindow); log.info('加载窗口已显示'); }; if (document.body) { createLoading(); } else { document.addEventListener('DOMContentLoaded', createLoading); } } function hideLoadingWindow() { if (loadingWindow) { loadingWindow.style.opacity = '0'; loadingWindow.style.transition = 'opacity 0.25s ease'; setTimeout(() => { if (loadingWindow) { loadingWindow.remove(); loadingWindow = null; const style = document.getElementById('cloud-script-loading-styles'); if (style) style.remove(); log.info('加载窗口已关闭'); } }, 250); } } window.__closeLoadingWindow__ = hideLoadingWindow; function showNotification(message, type = 'info') { if (!document.body) return; const colors = { info: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', success: 'linear-gradient(135deg, #10b981 0%, #059669 100%)', error: 'linear-gradient(135deg, #ef4444 0%, #dc2626 100%)' }; const toast = document.createElement('div'); toast.style.cssText = ` position: fixed; top: 20px; right: 20px; padding: 12px 20px; background: ${colors[type] || colors.info}; color: white; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 2147483647; font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; animation: slideIn 0.3s ease; `; toast.textContent = message; if (!document.getElementById('cloud-script-styles')) { const style = document.createElement('style'); style.id = 'cloud-script-styles'; style.textContent = ` @keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } } `; (document.head || document.documentElement).appendChild(style); } document.body.appendChild(toast); setTimeout(() => { toast.style.animation = 'slideIn 0.3s ease reverse'; setTimeout(() => toast.remove(), 300); }, 3000); } function showErrorPanel(message) { const render = () => { const errorDiv = document.createElement('div'); errorDiv.style.cssText = ` position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); padding: 24px 32px; background: white; border: 1px solid #fecaca; border-radius: 12px; color: #dc2626; z-index: 999999; font-size: 14px; text-align: center; box-shadow: 0 4px 12px rgba(0,0,0,0.1); `; errorDiv.innerHTML = `
❌
脚本加载失败
${message}
请检查网络连接或访问
脚本猫平台
`; document.body.appendChild(errorDiv); }; if (document.body) { render(); } else { document.addEventListener('DOMContentLoaded', render); } } async function checkBootstrapVersion() { try { log.info('检查引导脚本版本...'); const latest = await fetchVersionFromSources([ { name: 'gh-proxy', url: CONFIG.SOURCE.BOOTSTRAP_GH_PROXY_URL, updateUrl: CONFIG.SOURCE.BOOTSTRAP_GH_PROXY_URL, prefix: true, timeout: 20000 }, { name: '脚本猫 meta', url: CONFIG.VERSION_SERVER.BOOTSTRAP_VERSION_URL, updateUrl: CONFIG.VERSION_SERVER.BOOTSTRAP_UPDATE_URL, timeout: 30000 }, { name: 'CDN', url: CONFIG.SOURCE.BOOTSTRAP_CDN_URL, updateUrl: CONFIG.SOURCE.BOOTSTRAP_CDN_URL, timeout: 20000 } ]); const latestVersion = latest.version; const currentVersion = (typeof GM_info !== 'undefined' && GM_info && GM_info.script && GM_info.script.version) || ''; if (!currentVersion) { log.warn('无法获取启动器版本,跳过启动器更新检查'); return false; } if (compareVersion(latestVersion, currentVersion) <= 0) { log.success(`引导脚本已是最新版本 v${currentVersion}`); return false; } log.warn(`引导脚本有新版本: v${currentVersion} → v${latestVersion}`); const showDialog = () => { const mask = document.createElement('div'); mask.id = 'bootstrap-update-mask'; mask.style.cssText = ` position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(15, 23, 42, 0.45); backdrop-filter: blur(2px); z-index: 2147483646; `; const dialog = document.createElement('div'); dialog.id = 'bootstrap-update-dialog'; dialog.style.cssText = ` position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: #ffffff; border: 1px solid #e5e7eb; color: #111827; padding: 30px 40px; border-radius: 12px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15); z-index: 2147483647; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; text-align: center; max-width: 400px; `; dialog.innerHTML = `
⚠️
PP网课助手启动器需要更新
当前版本: v${currentVersion}
最新版本: v${latestVersion}
请先更新启动器,否则可能无法正常运行
安装完成后请刷新页面
立即更新 `; if (!document.getElementById('bootstrap-update-mask')) { document.body.appendChild(mask); } document.body.appendChild(dialog); document.body.style.overflow = 'hidden'; }; if (document.body) { showDialog(); } else { document.addEventListener('DOMContentLoaded', showDialog); } return true; } catch (e) { log.warn('检查引导脚本版本失败:', e && e.message); return false; } } function markReloadOnce() { try { if (sessionStorage.getItem(CONFIG.RELOAD_FLAG_KEY)) return false; sessionStorage.setItem(CONFIG.RELOAD_FLAG_KEY, '1'); setTimeout(() => { try { sessionStorage.removeItem(CONFIG.RELOAD_FLAG_KEY); } catch (e) {} }, 20000); return true; } catch (e) { return false; } } async function maintainAsync(executedVersion) { try { const needsBootstrapUpdate = await checkBootstrapVersion(); if (needsBootstrapUpdate) return; const latest = await fetchLatestVersion(); if (compareVersion(latest.version, executedVersion || '0.0.0') <= 0) { log.success(`主程序已是最新版本 v${executedVersion}`); return; } const result = await downloadScriptCode(); saveLocalCache(result.version, result.code); log.success(`已缓存新版本 v${result.version},刷新页面后生效`); if (document.body) { showNotification(`🔄 脚本 v${result.version} 已就绪,刷新后生效`, 'success'); } } catch (e) { log.warn('异步维护失败:', e && e.message); } } async function bootstrapAsync() { showLoadingWindow(); try { const needsBootstrapUpdate = await checkBootstrapVersion(); if (needsBootstrapUpdate) { log.warn('引导脚本需要更新,停止后续执行'); hideLoadingWindow(); return; } const result = await downloadScriptCode(); saveLocalCache(result.version, result.code); const cacheReady = (() => { try { return getLocalCache().code === result.code; } catch (e) { return false; } })(); if (cacheReady && isZhsExamPage() && markReloadOnce()) { log.warn('智慧树考试页首次安装:已缓存脚本,重载页面以对齐 document-start 时序'); hideLoadingWindow(); try { W.location.reload(); } catch (e) {} return; } executeCode(result.code, result.version, { guarded: true }); if (document.body) { showNotification(`🔄 脚本已加载 v${result.version}`, 'success'); } } catch (e) { log.error('脚本启动失败:', e && e.message); hideLoadingWindow(); showErrorPanel(e && e.message ? e.message : '未知错误'); } } const bootCache = getLocalCache(); let booted = false; if (isValidScriptCode(bootCache.code)) { const cachedVersion = bootCache.version || scriptVersionOf(bootCache.code); try { booted = executeCode(bootCache.code, cachedVersion, { guarded: false }); try { W.__PP_HOT_UPDATE_MODE__ = 'sync-cache'; } catch (e) {} log.info(`已按 document-start 同步路径执行缓存 v${cachedVersion}`); } catch (e) { booted = false; log.error('同步执行缓存失败:', e && e.message); if (evalAttempted) { log.error('主程序已产生副作用,本次不再重试;请刷新或清空缓存后重装'); } } } if (booted) { if (IS_TOP) maintainAsync(bootCache.version || scriptVersionOf(bootCache.code)); } else if (!IS_TOP) { if (!evalAttempted) log.info('子框架无可用缓存,等待顶层框架下载'); } else if (!evalAttempted) { bootstrapAsync(); } })();