// ==UserScript== // @name 🌸学习通全能小助手 (至尊进化版) // @namespace Gemini_Enhanced_Tool // @version 2.0.1 // @description 自动挂机视频、倍速播放、自动答题、自动切换章节。支持防检测随机延迟,屏蔽多端监控。 // @author Gemini & 雪中送碳 // @match *://*.chaoxing.com/* // @match *://*.edu.cn/* // @match *://*.nbdlib.cn/* // @match *://*.hnsyu.net/* // @run-at document-end // @grant unsafeWindow // @grant GM_xmlhttpRequest // @grant GM_setValue // @grant GM_getValue // @connect 14.29.190.187 // @connect tk.swk.tw // @license GPL-3.0-or-later // ==/UserScript== (function() { 'use strict'; // --- 【1. 用户配置区】 --- const SETTINGS = { videoRate: parseFloat(GM_getValue('rate', 1.0)), // 播放倍速 (建议不要超过2.0) autoAnswer: true, // 是否开启自动答题 autoSubmit: false, // 是否自动提交作业 targetAccuracy: 80, // 目标正确率 tikuToken: GM_getValue('tiku_token', ''), // 题库Token searchApi: 'http://tk.swk.tw/api/search.php', // 默认题库接口 }; const _w = unsafeWindow; const _d = _w.document; // --- 【2. 工具函数】 --- const Utils = { sleep: (ms) => new Promise(res => setTimeout(res, ms)), // 模拟人类随机延迟 randomWait: (min = 2000, max = 5000) => new Promise(res => setTimeout(res, Math.random() * (max - min) + min)), // 清洗题目文字 cleanStr: (str) => str ? str.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]/g, '').trim() : '', // 日志打印 log: (msg, color = '#ff69b4') => console.log(`%c[小助手] ${msg}`, `color: ${color}; font-weight: bold;`) }; // --- 【3. 核心屏蔽逻辑 (防检测)】 --- const Bypass = () => { // 屏蔽“正在监控”和“离开页面暂停” _w.confirm = () => true; _w.alert = () => true; // 破解鼠标失焦检测 (视线检测) try { Object.defineProperty(_d, 'hidden', { get: () => false }); Object.defineProperty(_d, 'visibilityState', { get: () => 'visible' }); } catch (e) {} // 屏蔽超星播放器某些事件上报 _w.onblur = null; _w.onfocus = null; }; // --- 【4. 视频挂机模块】 --- const VideoModule = { async run() { // 在 iframe 中寻找视频对象 const videos = _d.querySelectorAll('video'); if (videos.length === 0) return; for (let video of videos) { if (video.ended) continue; // 静音播放 video.muted = true; // 设置倍速 if (video.playbackRate !== SETTINGS.videoRate) { video.playbackRate = SETTINGS.videoRate; Utils.log(`倍速已调整为: ${SETTINGS.videoRate}`); } // 自动播放 if (video.paused) { await Utils.randomWait(1000, 3000); video.play().catch(() => {}); } // 播放完成自动跳转 (模拟点击) video.onended = async () => { Utils.log("本节视频播放完成,准备跳转下一节..."); await Utils.randomWait(3000, 6000); const nextBtn = _w.top.document.querySelector('.nextChapter') || _w.top.document.querySelector('.ncells .currents + li'); if (nextBtn) nextBtn.click(); }; } } }; // --- 【5. 答题模块】 --- const AnswerModule = { async query(question) { return new Promise((resolve) => { GM_xmlhttpRequest({ method: 'GET', url: `${SETTINGS.searchApi}?question=${encodeURIComponent(question)}&token=${SETTINGS.tikuToken}`, onload: (res) => { try { const json = JSON.parse(res.responseText); resolve(json.answer || json.data); } catch (e) { resolve(null); } }, onerror: () => resolve(null) }); }); }, async fill() { const items = _d.querySelectorAll('.TiMu'); // 学习通作业/测试容器选择器 if (items.length === 0) return; Utils.log(`发现题目数量: ${items.length},准备检索答案...`); for (let item of items) { const questionText = Utils.cleanStr(item.querySelector('.clearfix').innerText); const answer = await this.query(questionText); if (answer) { Utils.log(`题目: ${questionText.substring(0,10)}... -> 答案: ${answer}`, '#008000'); // 这里执行自动勾选逻辑 (根据具体DOM结构) this.matchAndClick(item, answer); } await Utils.randomWait(1000, 2000); // 题目间随机间隔 } }, matchAndClick(item, answer) { const options = item.querySelectorAll('li, .option'); options.forEach(opt => { const optText = Utils.cleanStr(opt.innerText); if (answer.includes(optText) || optText.includes(answer)) { opt.click(); } }); } }; // --- 【6. 初始化逻辑】 --- const init = async () => { Utils.log("脚本加载中..."); Bypass(); // 持续轮询任务状态 setInterval(() => { // 处理视频 VideoModule.run(); // 处理答题 (仅在作业或测试页面) if (window.location.href.includes('work') || window.location.href.includes('exam')) { if (SETTINGS.autoAnswer) AnswerModule.fill(); } }, 5000); // 每5秒检查一次状态 }; // 启动 if (window.top === window.self || window.location.href.includes('knowledge/cards')) { init(); } })();