// ==UserScript== // @name |🥇PP网课小助手|飘飘|热更新版本|超星学习通·知到智慧树·雨课堂| // @namespace 飘飘 // @version 2.5.0 // @author PIAOPIAO // @license MIT // @description (´-ω-`)《题库免费、AI 双校验,这合理吗?》|超星学习通·知到智慧树·雨课堂|视频自动播放倍速+章节任务+作业考试全题型自动答题|免费题库+Claude/ChatGPT/Gemini/DeepSeek等7款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 *://*.txootd.cn/* // @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 * // @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('请求超时')) }); }); } async function fetchRangeText(url, range, timeout) { const controller = typeof AbortController === 'function' ? new AbortController() : null; const timer = controller ? setTimeout(() => controller.abort(), timeout) : null; try { const response = await fetch(url, { method: 'GET', headers: { Range: range }, cache: 'no-store', ...(controller ? { signal: controller.signal } : {}) }); if (response.status !== 200 && response.status !== 206) { throw new Error(`HTTP ${response.status}`); } return await response.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.range && typeof fetch === 'function') { text = await fetchRangeText(source.url, source.range, 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, range: 'bytes=0-8191', timeout: 10000 }, { 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 = `