// ==UserScript== // @name 『学习通自动学习助手-不知名』-免费题库-高分题库 // @version 3.1.0 // @namespace bzm // @description 学习通助手,支持视频,作业、考试自动答题,免费高分题库。字体解密。 // @match *://*.chaoxing.com/* // @run-at document-end // @grant unsafeWindow // @grant GM_xmlhttpRequest // @grant GM_setValue // @grant GM_getValue // @grant GM_info // @grant GM_getResourceText // @grant GM_openInTab // @icon http://pan-yz.chaoxing.com/favicon.ico // @original-script https://scriptcat.org/zh-CN/script-show-page/5717 // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js // @require https://cdn.bootcdn.net/ajax/libs/limonte-sweetalert2/11.1.0/sweetalert2.all.min.js // @resource Table https://pkpkq.n1t.cn/font-decrypt/Table.json // @require https://pkpkq.n1t.cn/font-decrypt/TyprMd5.js // @connect tk.swk.tw // @connect pkpkq.n1t.cn // @connect soti.ucuc.net // @connect n1t.cn // @tag 免费搜题 // @tag 可选付费 // @antifeature payment 脚本存在第三方答题接口付费功能 // ==/UserScript== /*********************************自定义配置区******************************************************** */ var setting = { showBox: 1, // 显示脚本浮窗 maskImg: 1, // 显示皮卡丘 task: 0, // 只处理任务点任务 video: 1, // 处理视频 audio: 1, // 处理音频 rate: 1, // 视频/音频倍速 review: 0, // 复习模式 work: 1, // 测验自动处理 time: 5000, // 答题时间间隔(ms) sub: 0, // 测验自动提交 force: 0, // 测验强制提交 decrypt: 1, // 字体解密 examTurn: 1, // 考试自动跳转 examTurnTime: 1, // 考试自动跳转随机间隔 goodStudent: 0, // 好学生模式 alterTitle: 1, // 答案插入题目 autoLogin: 0, // 自动登录 phone: '', // 登录手机号 password: '' // 登录密码 } /**************************************************************************************************/ var _w = unsafeWindow, _l = location, _d = _w.document, $ = _w.jQuery || top.jQuery, UE = _w.UE; // 从 unsafeWindow 获取 Typr 和 md5,确保在沙盒环境中能访问 var TyprLib = null; var md5Lib = null; // API配置 - 支持多个备用接口 var API_SERVERS = [ { url: "https://soti.ucuc.net/api/search.php", name: "主接口" }, { url: "https://n1t.cn/api/search.php", name: "备用接口1" }, { url: "https://tk.swk.tw/api/search.php", name: "备用接口2" } ]; var CURRENT_SERVER_INDEX = 0; // 获取当前API URL function getCurrentApiUrl() { return API_SERVERS[CURRENT_SERVER_INDEX].url; } // 切换到下一个备用接口 function switchToNextApiServer() { CURRENT_SERVER_INDEX = (CURRENT_SERVER_INDEX + 1) % API_SERVERS.length; return getCurrentApiUrl(); } // 获取API密钥的函数 function getApiKey() { var key = GM_getValue('api_key', ''); return key; } // 检查是否有API密钥 function hasApiKey() { var key = getApiKey(); return key && key.trim() !== ''; } // 配额信息 - 从GM存储读取 function getQuotaInfo() { return { remaining: GM_getValue('quota_remaining', 0), free_remaining: GM_getValue('quota_free_remaining', 0), recharge_balance: GM_getValue('quota_recharge_balance', 0), today_free_usage: GM_getValue('quota_today_free_usage', 0) }; } var quotaInfo = getQuotaInfo(); var _mlist, _defaults, _domList, $subBtn, $saveBtn, $frame_c, $okBtn; var reportUrlChange = 0; var isProcessing = false; var isBoxHidden = false; var pikaqiuAdded = false; var pendingMissionCount = 0; var completedMissionCount = 0; var isJumping = false; var currentProcessingTask = null; var totalMissionCount = 0; var currentVideoInterval = null; var hasTriggeredNoTaskJump = false; // 日志队列 var logQueue = []; var logTimer = null; // 答案分割函数 function splitAnswer(answer) { if (!answer) return []; var parts = answer.split(/[#]+/).map(a => a.trim()).filter(a => a !== ''); if (parts.length === 0 && answer.trim() !== '') { return [answer.trim()]; } return parts; } // 保存配额信息到GM存储 function saveQuotaInfo() { GM_setValue('quota_remaining', quotaInfo.remaining); GM_setValue('quota_free_remaining', quotaInfo.free_remaining); GM_setValue('quota_recharge_balance', quotaInfo.recharge_balance); GM_setValue('quota_today_free_usage', quotaInfo.today_free_usage); } // 更新配额信息并保存 function updateQuotaInfo(newQuotaInfo) { if (newQuotaInfo) { quotaInfo.remaining = newQuotaInfo.remaining !== undefined ? newQuotaInfo.remaining : quotaInfo.remaining; quotaInfo.free_remaining = newQuotaInfo.free_remaining !== undefined ? newQuotaInfo.free_remaining : quotaInfo.free_remaining; quotaInfo.recharge_balance = newQuotaInfo.recharge_balance !== undefined ? newQuotaInfo.recharge_balance : quotaInfo.recharge_balance; quotaInfo.today_free_usage = newQuotaInfo.today_free_usage !== undefined ? newQuotaInfo.today_free_usage : quotaInfo.today_free_usage; saveQuotaInfo(); updateQuotaDisplay(); } } // 更新配额显示 function updateQuotaDisplay() { try { var targetDoc = top.document; if (!targetDoc.querySelector('#quotaInfo')) targetDoc = document; var $quotaInfo = $('#quotaInfo', targetDoc); if ($quotaInfo.length) { var remaining = quotaInfo.remaining; var hasKey = hasApiKey(); if (remaining > 0) { $quotaInfo.html(`📊 剩余次数: ${remaining} | 免费: ${quotaInfo.free_remaining}`); } else if (remaining === 0 && hasKey) { $quotaInfo.html(`⚠️ 次数已用完 | 点击充值`); } else if (!hasKey) { $quotaInfo.html('⚠️ 请先设置API密钥'); } else { $quotaInfo.html('📊 剩余次数: 加载中...'); } } } catch(e) {} } function getTopLogContainer() { try { var topDoc = top.document; var container = topDoc.getElementById('ne-21log'); if (container) return $(container); container = document.getElementById('ne-21log'); if (container) return $(container); return null; } catch(e) { return null; } } function flushLogs() { if (logQueue.length === 0) return; var container = getTopLogContainer(); if (container && container.length) { var logsToShow = logQueue.slice(); logQueue = []; for (var i = logsToShow.length - 1; i >= 0; i--) { container.prepend(logsToShow[i]); } container.scrollTop(0); } if (logTimer) { clearTimeout(logTimer); logTimer = null; } } function scheduleFlushLogs() { if (logTimer) return; logTimer = setTimeout(flushLogs, 100); } function log(str, color) { var time = new Date().toLocaleTimeString(); var logHtml = `
[${time}] ${str}
`; logQueue.push(logHtml); scheduleFlushLogs(); console.log(`[学习通助手][${time}]`, str); } // 显示皮卡丘 function showPikaqiu() { if (!setting.maskImg) return; if (pikaqiuAdded) return; try { var targetDoc = top.document; if (targetDoc.querySelector('#pikaqiu-img')) return; var imgHtml = ``; $(targetDoc.body).append(imgHtml); pikaqiuAdded = true; $('#pikaqiu-img', targetDoc).click(function() { var $box = $('#ne-21box', targetDoc); if ($box.length) { if ($box.css('display') === 'none') { $box.css('display', 'block'); isBoxHidden = false; } else { $box.css('display', 'none'); isBoxHidden = true; } } }); } catch(e) {} } $(document).keydown(function(e) { if (e.keyCode == 120) { var $box = $('#ne-21box'); if ($box.length === 0) return; if (isBoxHidden) { $box.css('display', 'block'); $box.css('opacity', '1'); isBoxHidden = false; log('📌 面板已显示', 'green'); } else { $box.css('display', 'none'); isBoxHidden = true; log('📌 面板已隐藏,按F9键恢复显示', 'blue'); } } }); // 测试API密钥(支持多接口) function testApi(key, serverIndex) { return new Promise((resolve, reject) => { var testQuestion = "test"; var testType = "单选题"; var testOptions = ["选项A", "选项B"]; var apiUrl = API_SERVERS[serverIndex || 0].url; var formData = `question=${encodeURIComponent(testQuestion)}&key=${encodeURIComponent(key)}&type=${encodeURIComponent(testType)}&options=${encodeURIComponent(JSON.stringify(testOptions))}`; var timeoutId = setTimeout(() => { reject('请求超时'); }, 10000); GM_xmlhttpRequest({ method: 'POST', url: apiUrl, headers: {'Content-Type': 'application/x-www-form-urlencoded'}, data: formData, timeout: 10000, onload: function(xhr) { clearTimeout(timeoutId); try { var res = JSON.parse(xhr.responseText); if (res.code == 1 || res.code == 400) { if (res.quota_info) { updateQuotaInfo(res.quota_info); } resolve(res); } else { reject(res.msg || '密钥无效'); } } catch(e) { reject('解析响应失败'); } }, onerror: function() { clearTimeout(timeoutId); reject('网络请求失败'); }, ontimeout: function() { clearTimeout(timeoutId); reject('请求超时'); } }); }); } function checkApiKeyBeforeAction(actionName) { var apiKey = getApiKey(); if (!apiKey || apiKey.trim() === '') { log(`❌ 无法执行${actionName}:请先在设置中配置API密钥`, 'red'); return false; } quotaInfo = getQuotaInfo(); if (quotaInfo.remaining <= 0 && quotaInfo.free_remaining <= 0) { log(`❌ 无法执行${actionName}:API次数已用完,请充值`, 'red'); return false; } return true; } // ========== getAnswer 函数(支持多接口备用,静默切换) ========== function getAnswer(type, questionText, optionsData, retryCount) { retryCount = retryCount || 0; var startServerIndex = retryCount; return new Promise((resolve, reject) => { var apiKey = getApiKey(); if (!apiKey || apiKey.trim() === '') { log('❌ 请先设置API密钥才能使用自动答题功能', 'red'); reject('NO_API_KEY'); return; } quotaInfo = getQuotaInfo(); if (quotaInfo.remaining <= 0 && quotaInfo.free_remaining <= 0) { log('❌ API次数已用完,无法获取答案', 'red'); reject('QUOTA_EXHAUSTED'); return; } var typeMap = {0:'单选题',1:'多选题',2:'填空题',3:'判断题',4:'简答题'}; var typeText = typeMap[type] || '单选题'; function tryServer(index) { if (index >= API_SERVERS.length) { log(`❌ 所有接口均无法获取答案`, 'red'); reject('所有接口均失败'); return; } var apiUrl = API_SERVERS[index].url; var formData = `question=${encodeURIComponent(questionText)}&key=${encodeURIComponent(apiKey)}&type=${encodeURIComponent(typeText)}`; if (optionsData && optionsData.length) { formData += `&options=${encodeURIComponent(JSON.stringify(optionsData))}`; } if (index === startServerIndex) { log(`🔍 请求答案 - 题型:${typeText} 题目:${questionText.substring(0, 40)}...`, 'blue'); } var timeoutId = setTimeout(() => { tryServer(index + 1); }, 15000); GM_xmlhttpRequest({ method: 'POST', url: apiUrl, headers: {'Content-Type': 'application/x-www-form-urlencoded'}, data: formData, timeout: 15000, onload: function(xhr) { clearTimeout(timeoutId); try { var res = JSON.parse(xhr.responseText); // 修复:正确处理返回数据格式 if (res.code == 1) { var answerData = null; // 处理 data 是数组的情况 if (Array.isArray(res.data) && res.data.length > 0) { if (res.data[0].answer) { answerData = res.data[0].answer; } else if (res.data[0].question && res.data[0].question !== "抱歉无答案") { answerData = res.data[0].question; } } else if (typeof res.data === 'string') { answerData = res.data; } else if (res.data && typeof res.data === 'object' && res.data.answer) { answerData = res.data.answer; } if (answerData && answerData !== "抱歉无答案" && !answerData.includes("无答案")) { if (res.quota_info) { updateQuotaInfo(res.quota_info); } CURRENT_SERVER_INDEX = index; GM_setValue('current_server_index', index); log(`✅ 获取答案成功`, 'purple'); resolve(answerData); return; } } // 接口返回成功但没有有效答案,尝试下一个接口 tryServer(index + 1); } catch(e) { tryServer(index + 1); } }, onerror: function() { clearTimeout(timeoutId); tryServer(index + 1); }, ontimeout: function() { clearTimeout(timeoutId); tryServer(index + 1); } }); } tryServer(startServerIndex); }); } // ========== 获取输入框数量 ========== function getBlankInputCount($question) { var count = 0; var $inputs = $question.find('.blankList2 input, input[type="text"][name*="answer"]'); if ($inputs.length) { var uniqueIdentifiers = new Set(); $inputs.each(function() { var name = $(this).attr('name'); var id = $(this).attr('id'); if (name) { uniqueIdentifiers.add(name); } else if (id) { uniqueIdentifiers.add(id); } else { var parentHtml = $(this).parent().html() || ''; uniqueIdentifiers.add($(this).index() + '_' + parentHtml.substring(0, 50)); } }); count = uniqueIdentifiers.size; if (count > 0) { return count; } } var $editorBlocks = $question.find('[data-editorindex]'); if ($editorBlocks.length) { var uniqueIndices = new Set(); $editorBlocks.each(function() { var idx = $(this).attr('data-editorindex'); if (idx !== undefined && idx !== null && idx !== '') { uniqueIndices.add(idx); } }); count = uniqueIndices.size; if (count > 0) { return count; } } var $pcInputs = $question.find('.Zy_ulTk .XztiHover1 textarea, .stem_answer .Answer .divText .textDIV textarea, .subEditor textarea'); if ($pcInputs.length) { var uniquePCInputs = new Set(); $pcInputs.each(function() { var id = $(this).attr('id'); var name = $(this).attr('name'); if (id) { uniquePCInputs.add(id); } else if (name) { uniquePCInputs.add(name); } else { uniquePCInputs.add($(this).index()); } }); count = uniquePCInputs.size; if (count > 0) { return count; } } if (count === 0) { return 1; } return count; } // ========== 填空题填写函数 ========== function fillBlankAnswer($question, answers, isPhoneMode, contextWindow) { var answerList = splitAnswer(answers); log(`📝 填空题答案: ${answerList.join(' | ')}`, 'blue'); if (isPhoneMode) { var $allInputs = $question.find('.blankList2 input, input[type="text"][name*="answer"]'); if ($allInputs.length) { var uniqueInputs = []; var seen = new Set(); $allInputs.each(function() { var name = $(this).attr('name'); var id = $(this).attr('id'); var key = name || id || $(this).index(); if (!seen.has(key)) { seen.add(key); uniqueInputs.push(this); } }); log(`📝 找到 ${uniqueInputs.length} 个填空输入框,准备填写`, 'blue'); $(uniqueInputs).each(function(i) { setTimeout(() => { var answerValue = answerList[i] !== undefined ? answerList[i] : (answerList[0] || ''); $(this).val(answerValue); $(this).trigger('input').trigger('change'); log(`✅ 填空题第${i+1}空已填写: ${answerValue}`, 'green'); }, i * 200); }); return true; } var $editorBlocks = $question.find('[data-editorindex]'); if ($editorBlocks.length) { var uniqueEditors = []; var seenIndices = new Set(); $editorBlocks.each(function() { var idx = $(this).attr('data-editorindex'); if (idx && !seenIndices.has(idx)) { seenIndices.add(idx); uniqueEditors.push(this); } }); log(`📝 找到 ${uniqueEditors.length} 个编辑器,准备填写`, 'blue'); uniqueEditors.forEach(function(editor, i) { var editorIndex = $(editor).attr('data-editorindex'); var itemId = $(editor).attr('data-itemid'); setTimeout(() => { try { var ueditor = null; if (contextWindow && contextWindow.editors && contextWindow.editors[editorIndex]) { ueditor = contextWindow.editors[editorIndex].ueditor; } if (!ueditor && contextWindow && contextWindow.UE && contextWindow.UE.instants) { var instantKey = 'ueditorInstant' + editorIndex; ueditor = contextWindow.UE.instants[instantKey]; } if (!ueditor && itemId && contextWindow && contextWindow.UE && contextWindow.UE.getEditor) { ueditor = contextWindow.UE.getEditor('ananas-editor-answer' + itemId); } if (ueditor) { var answerValue = answerList[i] !== undefined ? answerList[i] : (answerList[0] || ''); ueditor.setContent(answerValue); log(`✅ 填空题第${i+1}空已填写: ${answerValue}`, 'green'); } if (itemId) { var answerValue = answerList[i] !== undefined ? answerList[i] : (answerList[0] || ''); $('#answer' + itemId).val(answerValue).trigger('change'); } } catch(e) {} }, i * 300); }); return true; } return false; } var $pcInputs = $question.find('.Zy_ulTk .XztiHover1 textarea, .stem_answer .Answer .divText .textDIV textarea, .subEditor textarea'); if ($pcInputs.length) { var uniquePCInputs = []; var seenPC = new Set(); $pcInputs.each(function() { var id = $(this).attr('id'); var name = $(this).attr('name'); var key = id || name || $(this).index(); if (!seenPC.has(key)) { seenPC.add(key); uniquePCInputs.push(this); } }); log(`📝 找到 ${uniquePCInputs.length} 个填空输入框 (PC),准备填写`, 'blue'); $(uniquePCInputs).each(function(i) { setTimeout(() => { var $this = $(this); var answerValue = answerList[i] !== undefined ? answerList[i] : (answerList[0] || ''); if (UE && UE.getEditor && UE.getEditor($this.attr('id'))) { UE.getEditor($this.attr('id')).setContent(answerValue); } else { $this.val(answerValue); $this.trigger('input').trigger('change'); } log(`✅ 填空题第${i+1}空已填写: ${answerValue}`, 'green'); }, i * 200); }); return true; } return false; } // ========== 简答题填写函数 ========== function fillShortAnswer($question, answer, isPhoneMode, contextWindow) { log(`📝 简答题答案: ${answer.substring(0, 100)}...`, 'blue'); if (isPhoneMode) { var $editorBlocks = $question.find('[data-editorindex]'); if ($editorBlocks.length) { $editorBlocks.each(function(i) { var editorIndex = $(this).attr('data-editorindex'); var itemId = $(this).attr('data-itemid'); setTimeout(() => { try { var ueditor = null; if (contextWindow && contextWindow.editors && contextWindow.editors[editorIndex]) { ueditor = contextWindow.editors[editorIndex].ueditor; } if (!ueditor && contextWindow && contextWindow.UE && contextWindow.UE.instants) { var instantKey = 'ueditorInstant' + editorIndex; ueditor = contextWindow.UE.instants[instantKey]; } if (!ueditor && itemId && contextWindow && contextWindow.UE && contextWindow.UE.getEditor) { ueditor = contextWindow.UE.getEditor('ananas-editor-answer' + itemId); } if (ueditor) { ueditor.setContent(answer); log('✅ 简答题答案已填写', 'green'); } if (itemId) { $('#answer' + itemId).val(answer).trigger('change'); } } catch(e) {} }, 300); }); return true; } var $textarea = $question.find('textarea[name^="answer"], .answerTxt textarea'); if ($textarea.length) { $textarea.val(answer); $textarea.trigger('input').trigger('change'); return true; } return false; } var $ueTextarea = $question.find('textarea[name^="answerEditor"], .eidtDiv textarea, .divText textarea'); if ($ueTextarea.length) { var id = $ueTextarea.first().attr('id'); if (id && UE && UE.getEditor && UE.getEditor(id)) { try { UE.getEditor(id).setContent(answer); return true; } catch(e) {} } $ueTextarea.val(answer); $ueTextarea.trigger('input').trigger('change'); return true; } return false; } function tidyStr(s) { if (!s) return null; return s.replace(/<(?!img).*?>/g, "").replace(/^【.*?】\s*/, '').replace(/\s*(\d+\.\d+分)$/, '').trim().replace(/ /g, ''); } function tidyQuestion(s) { if (!s) return null; return s.replace(/<(?!img).*?>/g, "").replace(/^【.*?】\s*/, '').replace(/\s*(\d+\.\d+分)$/, '').replace(/^\d+[.、]/, '').trim(); } function waitForElement(selector, timeout = 30000) { return new Promise((resolve, reject) => { var start = Date.now(); var timer = setInterval(() => { if ($(selector).length) { clearInterval(timer); resolve(); } else if (Date.now() - start > timeout) { clearInterval(timer); reject(); } }, 500); }); } function getStr(str, start, end) { let res = str.match(new RegExp(`${start}(.*?)${end}`)); return res ? res[1] : null; } function parseUrlParams() { let query = window.location.search.substring(1); let vars = query.split("&"); let _p = {}; for (let i = 0; i < vars.length; i++) { let pair = vars[i].split("="); _p[pair[0]] = pair[1]; } return _p; } function getElement(parent, selector, timeout = 10000) { return new Promise(resolve => { var result = parent.querySelector(selector); if (result) return resolve(result); var timer; var observer = new MutationObserver(mutations => { for (var mutation of mutations) { for (var node of mutation.addedNodes) { if (node instanceof Element) { result = node.matches(selector) ? node : node.querySelector(selector); if (result) { observer.disconnect(); timer && clearTimeout(timer); return resolve(result); } } } } }); observer.observe(parent, { childList: true, subtree: true }); timer = setTimeout(() => { observer.disconnect(); resolve(null); }, timeout); }); } function getTaskParams() { try { var _iframeScripts = _d.scripts; for (let i = 0; i < _iframeScripts.length; i++) { if (_iframeScripts[i].innerHTML.indexOf('mArg = "";') != -1 && _iframeScripts[i].innerHTML.indexOf('==UserScript==') == -1) { var _p = getStr(_iframeScripts[i].innerHTML.replace(/\s/g, ""), 'try{mArg=', ';}catch'); return _p; } } return null; } catch (e) { return null; } } // 检查任务点是否真正完成 function isTaskCompleted(task) { if (!task) return false; if (task.isPassed === true) return true; if (task.status === 'completed' || task.status === 'finished') return true; if (task.finished === true) return true; return false; } // ========== 跳转函数 ========== function toNext() { if (isJumping) return; isJumping = true; log('🔄 检查是否有下一章节...', 'blue'); var nextBtn = null; try { nextBtn = top.document.querySelector('#mainid > .prev_next.next:not(.disabled)') || top.document.querySelector('#prevNextFocusNext:not(.disabled)') || top.document.querySelector('.prev_next.next:not(.disabled)') || $('.prev_next.next:not(.disabled)')[0]; if (nextBtn && !nextBtn.disabled && !nextBtn.classList.contains('disabled')) { log('✅ 找到下一节按钮,3秒后跳转', 'green'); setTimeout(() => { nextBtn.click(); log('📖 已点击跳转按钮', 'green'); isJumping = false; }, 3000); return true; } else { log('📚 课程已全部完成,无更多章节可跳转', 'green'); } } catch(e) { log('❌ 跳转失败: ' + e.message, 'red'); } isJumping = false; return false; } // 完成当前任务并处理下一个 function completeCurrentTask() { if (_mlist && _mlist.length > 0) { var completedTask = _mlist[0]; var taskName = completedTask.property ? (completedTask.property.name || completedTask.property.title || '未知') : '未知'; log(`✅ 完成任务: ${taskName}`, 'green'); _mlist.splice(0, 1); completedMissionCount++; log(`📋 任务进度: ${completedMissionCount}/${pendingMissionCount} | 剩余: ${_mlist.length}`, 'blue'); } if (_domList && _domList.length > 0) { _domList.splice(0, 1); } isProcessing = false; if (currentVideoInterval) { clearInterval(currentVideoInterval); currentVideoInterval = null; } if (_mlist && _mlist.length > 0) { log(`📋 还有 ${_mlist.length} 个任务点待处理,继续...`, 'green'); setTimeout(function() { missionStart(); }, 2000); } else { log('✅ 此页面所有任务处理完毕', 'green'); toNext(); } } function switchMission() { if (_mlist.length <= 0) { log('✅ 此页面任务处理完毕', 'green'); isProcessing = false; toNext(); return; } isProcessing = false; setTimeout(missionStart, 3000); } // ========== 任务处理 ========== function missionStart() { if (isProcessing) return; if (_mlist.length <= 0) { log('✅ 此页面任务处理完毕', 'green'); isProcessing = false; toNext(); return; } isProcessing = true; var _type = _mlist[0]['type']; var _dom = _domList[0]; var _task = _mlist[0]; currentProcessingTask = _task; if (_type == undefined) { _type = _mlist[0]['property']["module"]; } var handlers = { 'video': () => missionVideo(_dom, _task), 'audio': () => missionAudio(_dom, _task), 'workid': () => missionWork(_dom, _task), 'document': () => missionDoucument(_dom, _task), 'read': () => missionRead(_dom, _task), 'insertbook': () => missionBook(_dom, _task) }; if (handlers[_type]) { handlers[_type](); } else if (['insertimage'].includes(_type)) { log('ℹ️ 发现无需处理任务,跳过。', 'orange'); completeCurrentTask(); } else { log(`⚠️ 暂不支持处理此类型:${_type},跳过。`, 'red'); completeCurrentTask(); } } // ========== 视频处理函数 ========== function missionVideo(dom, obj) { if (!setting.video) { log('ℹ️ 用户设置不处理视频任务', 'orange'); completeCurrentTask(); return; } var { isPassed, property } = obj; var { name } = property; if (!setting.review && isPassed === true) { log(`✅ 视频:${name} 已完成,跳过`, 'green'); completeCurrentTask(); return; } var target = dom.length > 0 ? dom[0] : null; if (!target) { log('⚠️ 未找到视频iframe,3秒后重试', 'orange'); isProcessing = false; setTimeout(function() { missionVideo(dom, obj); }, 3000); return; } log(`🎬 处理视频:${name}`, 'purple'); var executed = false; var doc = target.contentDocument || target.contentWindow.document; if (currentVideoInterval) { clearInterval(currentVideoInterval); currentVideoInterval = null; } currentVideoInterval = setInterval(function() { var media = doc.querySelector('video') || doc.querySelector('audio'); if (media && !executed) { executed = true; log(`✅ ${name} 开始播放`, 'green'); media.pause(); media.muted = true; media.playbackRate = setting.rate > 1 ? Math.min(setting.rate, 16) : 1; media.play(); var resumePlay = function() { if (media.paused && !media.ended) { media.play(); log(`🔄 ${name} 恢复播放`, 'blue'); } }; media.addEventListener('pause', resumePlay); var onVideoEnd = function() { log(`✅ ${name} 播放完成`, 'green'); media.removeEventListener('pause', resumePlay); media.removeEventListener('ended', onVideoEnd); if (currentVideoInterval) { clearInterval(currentVideoInterval); currentVideoInterval = null; } completeCurrentTask(); }; media.addEventListener('ended', onVideoEnd); if (media.ended) { onVideoEnd(); } } else if (media && executed) { if (media.ended) { clearInterval(currentVideoInterval); currentVideoInterval = null; completeCurrentTask(); } } }, 1500); } function missionAudio(dom, obj) { if (!setting.audio) { log('ℹ️ 用户设置不处理音频任务', 'orange'); completeCurrentTask(); return; } var { isPassed, property } = obj; var { name } = property; if (!setting.review && isPassed === true) { log(`✅ 音频:${name} 已完成,跳过`, 'green'); completeCurrentTask(); return; } log(`🎵 处理音频:${name},等待5秒后完成`, 'purple'); setTimeout(function() { completeCurrentTask(); }, 5000); } function missionBook(dom, obj) { var jobId = obj['property']['jobid']; var name = obj['property']['bookname']; var jtoken = obj['jtoken']; var knowledgeId = _defaults['knowledgeid']; var courseId = _defaults['courseid']; var clazzId = _defaults['clazzId']; if (isTaskCompleted(obj)) { log(`✅ 读书:${name} 已完成,跳过`, 'green'); completeCurrentTask(); return; } $.ajax({ url: _l.protocol + "//" + _l.host + '/ananas/job?jobid=' + jobId + '&knowledgeid=' + knowledgeId + '&courseid=' + courseId + '&clazzid=' + clazzId + '&jtoken=' + jtoken + '&_dc=' + Date.now(), method: 'GET', success: function(res) { log('📚 读书:' + name + (res.msg || '完成'), 'green'); completeCurrentTask(); }, error: function() { log(`❌ 读书:${name} 处理失败,3秒后重试`, 'red'); isProcessing = false; setTimeout(function() { missionBook(dom, obj); }, 3000); } }); } function missionDoucument(dom, obj) { var jobId = obj['property']['jobid']; var name = obj['property']['name']; var jtoken = obj['jtoken']; var knowledgeId = _defaults['knowledgeid']; var courseId = _defaults['courseid']; var clazzId = _defaults['clazzId']; if (isTaskCompleted(obj)) { log(`✅ 文档:${name} 已完成,跳过`, 'green'); completeCurrentTask(); return; } $.ajax({ url: _l.protocol + "//" + _l.host + '/ananas/job/document?jobid=' + jobId + '&knowledgeid=' + knowledgeId + '&courseid=' + courseId + '&clazzid=' + clazzId + '&jtoken=' + jtoken + '&_dc=' + Date.now(), method: 'GET', success: function(res) { log('📄 文档:' + name + (res.msg || '完成'), 'green'); completeCurrentTask(); }, error: function() { log(`❌ 文档:${name} 处理失败,3秒后重试`, 'red'); isProcessing = false; setTimeout(function() { missionDoucument(dom, obj); }, 3000); } }); } function missionRead(dom, obj) { var jobId = obj['property']['jobid']; var name = obj['property']['title']; var jtoken = obj['jtoken']; var knowledgeId = _defaults['knowledgeid']; var courseId = _defaults['courseid']; var clazzId = _defaults['clazzId']; if (isTaskCompleted(obj)) { log(`✅ 阅读:${name} 已完成,跳过`, 'green'); completeCurrentTask(); return; } $.ajax({ url: _l.protocol + '//' + _l.host + '/ananas/job/readv2?jobid=' + jobId + '&knowledgeid=' + knowledgeId + '&courseid=' + courseId + '&clazzid=' + clazzId + '&jtoken=' + jtoken + '&_dc=' + Date.now(), method: 'GET', success: function(res) { log('📖 阅读:' + name + (res.msg || '完成'), 'green'); completeCurrentTask(); }, error: function() { log(`❌ 阅读:${name} 处理失败,3秒后重试`, 'red'); isProcessing = false; setTimeout(function() { missionRead(dom, obj); }, 3000); } }); } function missionWork(dom, obj) { if (!setting.work) { log('ℹ️ 用户设置不自动处理测验', 'orange'); completeCurrentTask(); return; } if (!checkApiKeyBeforeAction('自动答题')) { completeCurrentTask(); return; } var isDo = true; if (setting.task && obj['jobid'] == undefined) { isDo = false; } if (isDo) { if (obj['jobid'] !== undefined) { var phoneWeb = _l.protocol + '//' + _l.host + '/work/phone/work?workId=' + obj['jobid'].replace('work-', '') + '&courseId=' + _defaults['courseid'] + '&clazzId=' + _defaults['clazzId'] + '&knowledgeId=' + _defaults['knowledgeid'] + '&jobId=' + obj['jobid'] + '&enc=' + obj['enc']; log('📝 准备处理测验', 'purple'); setTimeout(function() { startDoPhoneCyWork(0, dom, phoneWeb, obj); }, 3000); } else { setTimeout(function() { startDoCyWork(0, dom, obj); }, 3000); } } else { log('ℹ️ 用户设置只处理属于任务点的任务', 'orange'); completeCurrentTask(); } } function startDoPhoneCyWork(index, doms, phoneWeb, taskObj) { if (index == doms.length) { log('✅ 此页面全部测验已处理完毕', 'green'); completeCurrentTask(); return; } getElement($(doms[index]).contents()[0], 'iframe').then(function(iframe) { if (!iframe) { setTimeout(function() { startDoPhoneCyWork(index, doms, phoneWeb, taskObj); }, 5000); return; } var workIframe = $(iframe); var workStatus = workIframe.contents().find('.newTestCon .newTestTitle .testTit_status').text().trim(); if (!workStatus) { _domList.splice(0, 1); isProcessing = false; setTimeout(switchMission, 2000); return; } if (workStatus.indexOf("待做") != -1 || workStatus.indexOf("待完成") != -1 || workStatus.indexOf("未达到及格线") != -1) { workIframe.attr('src', phoneWeb); getElement($(doms[index]).contents()[0], 'iframe[src="' + phoneWeb + '"]').then(function() { setTimeout(function() { doPhoneWork(workIframe.contents(), taskObj); }, 3000); }); } else if (workStatus.indexOf('待批阅') != -1) { _mlist.splice(0, 1); _domList.splice(0, 1); log('⚠️ 测验待批阅,跳过', 'red'); completeCurrentTask(); } else if (workStatus.indexOf('已完成') != -1 || workStatus.indexOf('已交') != -1) { log('✅ 测验已完成,跳过', 'green'); completeCurrentTask(); } else { _mlist.splice(0, 1); _domList.splice(0, 1); log('⚠️ 未知状态,跳过', 'red'); completeCurrentTask(); } }); } function doPhoneWork($dom, taskObj) { var $cy = $dom.find('.Wrappadding form'); $subBtn = $cy.find('.zquestions .zsubmit .btn-ok-bottom'); $okBtn = $dom.find('#okBtn'); $saveBtn = $cy.find('.zquestions .zsubmit .btn-save'); var TimuList = $cy.find('.zquestions .Py-mian1'); startDoPhoneTimu(0, TimuList, taskObj); } // ========== 修复后的 startDoPhoneTimu 函数 - 正确识别题型 ========== function startDoPhoneTimu(index, TimuList, taskObj) { if (index == TimuList.length) { if (setting.sub) { log('✅ 测验处理完成,准备自动提交。', 'green'); setTimeout(() => { $subBtn.click(); setTimeout(() => { $okBtn.click(); log('✅ 提交成功', 'green'); completeCurrentTask(); }, 3000); }, 5000); } else if (setting.force) { log('⚠️ 存在无答案题目,强制提交', 'red'); setTimeout(() => { $subBtn.click(); setTimeout(() => { $okBtn.click(); log('✅ 提交成功', 'green'); completeCurrentTask(); }, 3000); }, 5000); } else { log('💾 测验处理完成,自动保存', 'green'); setTimeout(() => { $saveBtn.click(); setTimeout(() => { log('✅ 保存成功', 'green'); completeCurrentTask(); }, 3000); }, 5000); } return; } var contextWindow = TimuList[index] ? (TimuList[index].ownerDocument.defaultView || unsafeWindow) : unsafeWindow; var $question = $(TimuList[index]); // 获取题目HTML(解密前的原始内容,用于识别题型) var questionHtml = $question.find('.Py-m1-title').html() || $question.html() || ''; // 题型识别 - 从方括号中提取题型 var typeName = ''; var bracketMatch = questionHtml.match(/\[(.*?)\]/); if (bracketMatch && bracketMatch[1]) { typeName = bracketMatch[1]; } // 如果没有方括号,尝试从其他格式匹配 if (!typeName) { var chineseMatch = questionHtml.match(/(单选题|多选题|填空题|判断题|简答题)/); if (chineseMatch) { typeName = chineseMatch[1]; } } var typeMap = { '单选题': 0, '多选题': 1, '填空题': 2, '判断题': 3, '简答题': 4 }; var _type = typeMap[typeName]; // 如果题型仍然未识别,通过DOM结构判断 if (_type === undefined) { if ($question.find('.answerList.singleChoice li').length) _type = 0; else if ($question.find('.answerList.multiChoice li').length) _type = 1; else if ($question.find('.blankList2 input').length) _type = 2; else if ($question.find('.answerList.panduan li').length) _type = 3; else if ($question.find('textarea').length) _type = 4; } if (_type === undefined) { log(`⚠️ 第${index + 1}题无法识别题型,跳过`, 'orange'); setTimeout(() => startDoPhoneTimu(index + 1, TimuList, taskObj), setting.time); return; } // 获取纯净的题目文本(去除HTML标签和题型标记) var _question = tidyQuestion(questionHtml); // 移除方括号内的题型标记 _question = _question.replace(/\[.*?\]/, '').trim(); // 移除开头的序号(如"1."、"1、"等) _question = _question.replace(/^\d+[.、]?\s*/, ''); var checkAnswered = function() { if (_type == 0 || _type == 1) { var $opts = _type == 0 ? $question.find('.answerList.singleChoice li') : $question.find('.answerList.multiChoice li'); for (var i = 0; i < $opts.length; i++) { if ($($opts[i]).attr('aria-label')) return true; } } else if (_type == 2) { var $inputs = $question.find('.blankList2 input'); if ($inputs.length && $inputs.first().val() && $inputs.first().val().trim() !== '') return true; var $editorBlocks = $question.find('[data-editorindex]'); if ($editorBlocks.length) { var hasContent = false; $editorBlocks.each(function() { var itemId = $(this).attr('data-itemid'); if (itemId && $('#answer' + itemId).val() && $('#answer' + itemId).val().trim() !== '') { hasContent = true; } }); if (hasContent) return true; } } else if (_type == 3) { var $pd = $question.find('.answerList.panduan li'); for (var i = 0; i < $pd.length; i++) { if ($($pd[i]).attr('aria-label')) return true; } } else if (_type == 4) { var $ta = $question.find('textarea[name^="answer"]'); if ($ta.length && $ta.first().val() && $ta.first().val().trim() !== '') return true; var $editorBlocks = $question.find('[data-editorindex]'); if ($editorBlocks.length) { var hasContent = false; $editorBlocks.each(function() { var itemId = $(this).attr('data-itemid'); if (itemId && $('#answer' + itemId).val() && $('#answer' + itemId).val().trim() !== '') { hasContent = true; } }); if (hasContent) return true; } } return false; }; if (checkAnswered()) { log(`📌 第${index + 1}题已作答,跳过`, 'green'); setTimeout(() => startDoPhoneTimu(index + 1, TimuList, taskObj), 30); return; } var $opts = []; var optsText = []; var optionsData = []; var pureQuestion = _question; if (_type == 0 || _type == 1) { $opts = _type == 0 ? $question.find('.answerList.singleChoice li') : $question.find('.answerList.multiChoice li'); $opts.each(function() { optsText.push(tidyStr($(this).html()).replace(/^[A-Z]\s*\n\s*/, '').trim()); }); optionsData = optsText; } else if (_type == 2) { var blankCount = getBlankInputCount($question); optionsData = [blankCount.toString()]; log(`📝 填空题传入空数量: ${blankCount}`, 'blue'); } else if (_type == 3) { optionsData = ["对", "错"]; } else if (_type == 4) { optionsData = ["1"]; } getAnswer(_type, pureQuestion, optionsData).then((agrs) => { if (agrs == '暂无答案' || !agrs) { log(`⚠️ 第${index + 1}题无法获取答案,跳过`, 'red'); setTimeout(() => startDoPhoneTimu(index + 1, TimuList, taskObj), setting.time); return; } if (setting.alterTitle) { $question.find('.Py-m1-title').html($question.find('.Py-m1-title').html() + `

📖 ${agrs}

`); } if (_type == 0) { var idx = optsText.findIndex(t => t == agrs); if (idx != -1) $question.find('.answerList.singleChoice li').eq(idx).click(); else log(`⚠️ 未找到匹配选项: ${agrs}`, 'orange'); } else if (_type == 1) { var ansArr = splitAnswer(agrs); $opts.each((i, t) => { if (ansArr.includes(optsText[i])) { setTimeout(() => $(t).click(), 300); } }); } else if (_type == 2) { fillBlankAnswer($question, agrs, true, contextWindow); } else if (_type == 3) { var isTrue = ['正确','是','对','√','T','ri','true'].some(k => agrs.toLowerCase().includes(k.toLowerCase())); var $pd = $question.find('.answerList.panduan li'); $pd.each((i, t) => { var val = $(t).attr('val-param'); if ((isTrue && val == 'true') || (!isTrue && val == 'false')) { $(t).click(); } }); } else if (_type == 4) { fillShortAnswer($question, agrs, true, contextWindow); } log(`✅ 第${index + 1}题自动答题成功`, 'green'); setTimeout(() => startDoPhoneTimu(index + 1, TimuList, taskObj), setting.time); }).catch((err) => { log(`⚠️ 第${index + 1}题获取答案失败: ${err}`, 'orange'); setTimeout(() => startDoPhoneTimu(index + 1, TimuList, taskObj), setting.time); }); } function startDoCyWork(index, doms, taskObj) { if (index == doms.length) { log('✅ 此页面全部测验已处理完毕', 'green'); completeCurrentTask(); return; } getElement($(doms[index]).contents()[0], 'iframe').then(function(iframe) { if (!iframe) { setTimeout(function() { startDoCyWork(index, doms, taskObj); }, 5000); return; } var workIframe = $(iframe); var workStatus = workIframe.contents().find(".newTestCon .newTestTitle .testTit_status").text().trim(); if (!workStatus) { _domList.splice(0, 1); isProcessing = false; setTimeout(switchMission, 2000); return; } if (workStatus.indexOf("待做") != -1 || workStatus.indexOf("待完成") != -1) { log('📝 准备处理测验', 'purple'); setTimeout(function() { doWork(index, doms, iframe, taskObj); }, 5000); } else if (workStatus.indexOf('待批阅') != -1) { _mlist.splice(0, 1); _domList.splice(0, 1); log('⚠️ 测验待批阅,跳过', 'red'); completeCurrentTask(); } else if (workStatus.indexOf('已完成') != -1 || workStatus.indexOf('已交') != -1) { log('✅ 测验已完成,跳过', 'green'); completeCurrentTask(); } else { _mlist.splice(0, 1); _domList.splice(0, 1); log('⚠️ 未知状态,跳过', 'red'); completeCurrentTask(); } }); } function doWork(index, doms, dom, taskObj) { $frame_c = $(dom).contents(); var $CyHtml = $frame_c.find('.CeYan'); var TiMuList = $CyHtml.find('.TiMu'); $subBtn = $frame_c.find(".ZY_sub").find(".btnSubmit"); $saveBtn = $frame_c.find(".ZY_sub").find(".btnSave"); startDoWork(index, doms, 0, TiMuList, taskObj); } // PC端答题函数 function startDoWork(index, doms, c, TiMuList, taskObj) { if (c == TiMuList.length) { if (setting.sub) { log('✅ 测验处理完成,准备自动提交。', 'green'); setTimeout(() => { $subBtn.click(); setTimeout(() => { $frame_c.find('#confirmSubWin > div > div > a.bluebtn').click(); log('✅ 提交成功', 'green'); completeCurrentTask(); }, 3000); }, 5000); } else if (setting.force) { log('⚠️ 存在无答案题目,强制提交', 'red'); setTimeout(() => { $subBtn.click(); setTimeout(() => { $frame_c.find('#confirmSubWin > div > div > a.bluebtn').click(); log('✅ 提交成功', 'green'); completeCurrentTask(); }, 3000); }, 5000); } else { log('💾 测验处理完成,自动保存', 'green'); setTimeout(() => { $saveBtn.click(); setTimeout(() => { log('✅ 保存成功', 'green'); completeCurrentTask(); }, 3000); }, 5000); } return; } var $question = $(TiMuList[c]); var questionHtml = $question.find('.Zy_TItle.clearfix > div').html() || $question.html() || ''; // 题型识别 var typeName = ''; var bracketMatch = questionHtml.match(/【(.*?)】/); if (bracketMatch && bracketMatch[1]) { typeName = bracketMatch[1]; } if (!typeName) { var chineseMatch = questionHtml.match(/(单选题|多选题|填空题|判断题|简答题)/); if (chineseMatch) { typeName = chineseMatch[1]; } } var typeMap = { '单选题': 0, '多选题': 1, '填空题': 2, '判断题': 3, '简答题': 4 }; var _TimuType = typeMap[typeName]; if (_TimuType === undefined) { if ($question.find('.Zy_ulTop li').length) { _TimuType = $question.find('input[type="checkbox"]').length ? 1 : 0; } else if ($question.find('.Zy_ulTk .XztiHover1').length) { _TimuType = 2; } else { _TimuType = 4; } } // 获取纯净题目文本 var _question = tidyQuestion(questionHtml); _question = _question.replace(/【.*?】/, '').trim(); _question = _question.replace(/^\d+[.、]?\s*/, ''); var $opts = []; var optsText = []; var optionsData = []; var pureQuestion = _question; if (_TimuType == 0 || _TimuType == 1) { $opts = $question.find('.Zy_ulTop li a'); $opts.each(function() { optsText.push(tidyStr($(this).html())); }); optionsData = optsText; } else if (_TimuType == 2) { var blankCount = getBlankInputCount($question); optionsData = [blankCount.toString()]; } else if (_TimuType == 3) { optionsData = ["对", "错"]; } else if (_TimuType == 4) { optionsData = ["1"]; } getAnswer(_TimuType, pureQuestion, optionsData).then((agrs) => { if (agrs && agrs != '暂无答案') { if (setting.alterTitle) { $question.find('.Zy_TItle.clearfix > div').html($question.find('.Zy_TItle.clearfix > div').html() + `

📖 ${agrs}

`); } if (_TimuType == 0) { var idx = optsText.findIndex(t => t == agrs); if (idx != -1) $($opts[idx]).parent().click(); } else if (_TimuType == 1) { var ansArr = splitAnswer(agrs); $opts.each((i, t) => { if (ansArr.includes(optsText[i])) $($opts[i]).parent().click(); }); } else if (_TimuType == 2) { fillBlankAnswer($question, agrs, false, null); } else if (_TimuType == 3) { var isTrue = ['正确','是','对','√','T','ri','true'].some(k => agrs.toLowerCase().includes(k.toLowerCase())); $opts.each((i, t) => { var txt = tidyStr($(t).html()); if ((isTrue && (txt == '对' || txt == '√' || txt == '正确')) || (!isTrue && (txt == '错' || txt == '×' || txt == '错误'))) { $($opts[i]).parent().click(); } }); } else if (_TimuType == 4) { fillShortAnswer($question, agrs, false, null); } log(`✅ PC第${c + 1}题自动答题成功`, 'green'); } else { log(`⚠️ PC第${c + 1}题无法获取答案`, 'orange'); } setTimeout(() => startDoWork(index, doms, c + 1, TiMuList, taskObj), setting.time); }).catch(() => { setTimeout(() => startDoWork(index, doms, c + 1, TiMuList, taskObj), setting.time); }); } // ========== 作业处理 ========== function missonHomeWork() { log('📝 开始处理作业', 'green'); if (!checkApiKeyBeforeAction('作业自动答题')) return; var $_homeworktable = $('.mark_table').find('form'); var TimuList = $_homeworktable.find('.questionLi'); doHomeWork(0, TimuList); } function doHomeWork(index, TiMuList) { if (index == TiMuList.length) { log('✅ 作业题目已全部完成', 'green'); return; } var $question = $(TiMuList[index]); var typeName = $question.attr('typename'); var typeMap = { '单选题': 0, '多选题': 1, '填空题': 2, '判断题': 3, '简答题': 4 }; var _type = typeMap[typeName]; var _questionFull = $question.find('.mark_name').html() || ''; var _question = tidyQuestion(_questionFull); _question = _question.replace(/^[(].*?[)]/, '').trim(); _question = _question.replace(/^\d+[.、]?\s*/, ''); if (_type === undefined) { var _answerTmpArr = $question.find('.stem_answer').find('.answer_p'); if (_answerTmpArr && _answerTmpArr.length > 0) { _type = $question.find('input[type="checkbox"]').length ? 1 : 0; } else if ($question.find('.stem_answer').find('.divText textarea').length) { _type = 4; } } if (_type === undefined) { log(`⚠️ 作业第${index + 1}题无法识别题型,跳过`, 'orange'); setTimeout(() => doHomeWork(index + 1, TiMuList), setting.time); return; } var checkAnswered = function() { if (_type == 0 || _type == 1) { var $opts = $question.find('.stem_answer .answer_p'); for (var i = 0; i < $opts.length; i++) { if ($($opts[i]).parent().find('span').attr('class') && $($opts[i]).parent().find('span').attr('class').indexOf('check_answer') != -1) { return true; } } } else if (_type == 2) { var $inputs = $question.find('.stem_answer .Answer .divText .textDIV textarea'); if ($inputs.length && $inputs.val() && $inputs.val().trim() !== '') return true; } else if (_type == 3) { var $opts = $question.find('.stem_answer .answer_p'); for (var i = 0; i < $opts.length; i++) { if ($($opts[i]).parent().find('span').attr('class') && $($opts[i]).parent().find('span').attr('class').indexOf('check_answer') != -1) { return true; } } } else if (_type == 4) { var $ta = $question.find('.stem_answer .eidtDiv textarea'); if ($ta.length && $ta.val() && $ta.val().trim() !== '') return true; } return false; }; if (checkAnswered()) { log(`📌 作业第${index + 1}题已作答,跳过`, 'green'); setTimeout(() => doHomeWork(index + 1, TiMuList), 30); return; } var $opts = []; var optsText = []; var optionsData = []; var pureQuestion = _question; if (_type == 0 || _type == 1) { $opts = $question.find('.stem_answer .answer_p'); $opts.each(function() { optsText.push(tidyStr($(this).html())); }); optionsData = optsText; } else if (_type == 2) { var blankCount = getBlankInputCount($question); optionsData = [blankCount.toString()]; } else if (_type == 3) { optionsData = ["对", "错"]; } else if (_type == 4) { optionsData = ["1"]; } getAnswer(_type, pureQuestion, optionsData).then((agrs) => { if (agrs && agrs != '暂无答案') { if (setting.alterTitle) { $question.find('.mark_name').html($question.find('.mark_name').html() + `

📖 ${agrs}

`); } if (_type == 0) { var idx = optsText.findIndex(t => t == agrs); if (idx != -1) $($opts[idx]).parent().click(); } else if (_type == 1) { var ansArr = splitAnswer(agrs); $opts.each((i, t) => { if (ansArr.includes(optsText[i])) { setTimeout(() => $($opts[i]).parent().click(), 300); } }); } else if (_type == 2) { fillBlankAnswer($question, agrs, false, null); } else if (_type == 3) { var isTrue = ['正确','是','对','√','T','ri','true'].some(k => agrs.toLowerCase().includes(k.toLowerCase())); $opts.each((i, t) => { var txt = tidyStr($(t).html()); if ((isTrue && (txt == '对' || txt == '√' || txt == '正确')) || (!isTrue && (txt == '错' || txt == '×' || txt == '错误'))) { $($opts[i]).parent().click(); } }); } else if (_type == 4) { fillShortAnswer($question, agrs, false, null); } log(`✅ 作业第${index + 1}题自动答题成功`, 'green'); } else { log(`⚠️ 作业第${index + 1}题无法获取答案`, 'orange'); } setTimeout(() => doHomeWork(index + 1, TiMuList), setting.time); }).catch(() => { setTimeout(() => doHomeWork(index + 1, TiMuList), setting.time); }); } // ========== 考试处理 ========== function missonExam() { if (!checkApiKeyBeforeAction('考试自动答题')) return; var $_examtable = $('.mark_table').find('.whiteDiv'); var _questionFull = tidyStr($_examtable.find('h3.mark_name').html().trim()); var typeName = _questionFull.match(/[(](.*?),.*?分[)]|$/)[1]; var typeMap = { '单选题': 0, '多选题': 1, '填空题': 2, '判断题': 3, '简答题': 4 }; var _qType = typeMap[typeName]; var _question = tidyQuestion(_questionFull.replace(/[(].*?分[)]/, '').replace(/^\s*/, '')); _question = _question.replace(/^\d+[.、]?\s*/, ''); var $_ansdom = $_examtable.find('#submitTest').find('.stem_answer'); if (_qType === undefined) { var $opts = $_ansdom.find('.clearfix.answerBg .fl.answer_p'); if ($opts.length) { _qType = $_ansdom.find('input[type="checkbox"]').length ? 1 : 0; } else if ($_ansdom.find('.Answer .divText .subEditor textarea').length) { _qType = 4; } } if (_qType === undefined) { log('⚠️ 考试题目无法识别题型,跳过', 'orange'); toNextExam(); return; } var checkAnswered = function() { if (_qType == 0 || _qType == 1) { var $opts = $_ansdom.find('.clearfix.answerBg .fl.answer_p'); for (var i = 0; i < $opts.length; i++) { if ($($opts[i]).parent().find('span').attr('class') && $($opts[i]).parent().find('span').attr('class').indexOf('check_answer') != -1) { return true; } } } else if (_qType == 2) { var $inputs = $_ansdom.find('.Answer .divText .subEditor textarea'); if ($inputs.length && $inputs.val() && $inputs.val().trim() !== '') return true; } else if (_qType == 4) { var $ta = $_ansdom.find('.subEditor textarea'); if ($ta.length && $ta.val() && $ta.val().trim() !== '') return true; } return false; }; if (checkAnswered()) { log('📌 考试此题已作答,跳过', 'green'); toNextExam(); return; } var $opts = []; var optsText = []; var optionsData = []; var pureQuestion = _question; if (_qType == 0 || _qType == 1) { $opts = $_ansdom.find('.clearfix.answerBg .fl.answer_p'); $opts.each(function() { optsText.push(tidyStr($(this).html())); }); optionsData = optsText; } else if (_qType == 2) { var blankCount = getBlankInputCount($_ansdom); optionsData = [blankCount.toString()]; } else if (_qType == 4) { optionsData = ["1"]; } else if (_qType == 3) { optionsData = ["对", "错"]; } getAnswer(_qType, pureQuestion, optionsData).then((agrs) => { if (agrs && agrs != '暂无答案') { if (setting.alterTitle) { $_examtable.find('h3.mark_name').html($_examtable.find('h3.mark_name').html() + `📖 ${agrs}`); } if (_qType == 0) { var idx = optsText.findIndex(t => t == agrs); if (idx != -1) { var $target = $($opts[idx]).parent(); if (setting.goodStudent) { $target.find('span').css('font-weight', 'bold'); log('📝 好学生模式:答案已加粗,未自动选择', 'blue'); } else { $target.click(); } } } else if (_qType == 1) { var ansArr = splitAnswer(agrs); $opts.each((i, t) => { if (ansArr.includes(optsText[i])) { if (setting.goodStudent) { $($opts[i]).parent().find('span').css('font-weight', 'bold'); } else { setTimeout(() => $($opts[i]).parent().click(), 300); } } }); } else if (_qType == 2) { fillBlankAnswer($_ansdom, agrs, false, null); } else if (_qType == 3) { var isTrue = ['正确','是','对','√','T','ri','true'].some(k => agrs.toLowerCase().includes(k.toLowerCase())); $opts.each((i, t) => { var txt = tidyStr($(t).html()); if ((isTrue && (txt == '对' || txt == '√' || txt == '正确')) || (!isTrue && (txt == '错' || txt == '×' || txt == '错误'))) { $($opts[i]).parent().click(); } }); } else if (_qType == 4) { fillShortAnswer($_ansdom, agrs, false, null); } log('✅ 考试自动答题成功', 'green'); } else { log('⚠️ 考试无法获取答案', 'orange'); } setTimeout(() => toNextExam(), setting.time); }).catch(() => { setTimeout(() => toNextExam(), setting.time); }); } function toNextExam() { if (setting.examTurn) { var $nextbtn = $('.mark_table .whiteDiv .nextDiv a.jb_btn'); var delay = setting.examTurnTime ? 2000 + (Math.floor(Math.random() * 5 + 1) * 1000) : 2000; setTimeout(() => $nextbtn.click(), delay); log(`⏭️ ${delay/1000}秒后自动跳转下一题`, 'blue'); } } // ==================== 字体解密功能(完全修复版) ==================== function decryptFont() { var TyprInstance = null; var md5Instance = null; if (typeof unsafeWindow !== 'undefined' && unsafeWindow.Typr) { TyprInstance = unsafeWindow.Typr; } else if (typeof window !== 'undefined' && window.Typr) { TyprInstance = window.Typr; } else if (typeof Typr !== 'undefined') { TyprInstance = Typr; } if (typeof unsafeWindow !== 'undefined' && unsafeWindow.md5) { md5Instance = unsafeWindow.md5; } else if (typeof window !== 'undefined' && window.md5) { md5Instance = window.md5; } else if (typeof md5 !== 'undefined') { md5Instance = md5; } if (!TyprInstance || !md5Instance || !TyprInstance.U) { setTimeout(function() { decryptFont(); }, 1000); return; } var $tip = $('style:contains(font-cxsecret)'); if (!$tip.length) { return; } try { var styleText = $tip.text(); var fontBase64 = null; var match1 = styleText.match(/base64,([\w\W]+?)'/); if (match1 && match1[1]) fontBase64 = match1[1]; if (!fontBase64) { var match2 = styleText.match(/url\("data:application\/font-woff;charset=utf-8;base64,([\w\W]+?)"\)/); if (match2 && match2[1]) fontBase64 = match2[1]; } if (!fontBase64) { var match3 = styleText.match(/url\('data:application\/font-woff;charset=utf-8;base64,([\w\W]+?)'\)/); if (match3 && match3[1]) fontBase64 = match3[1]; } if (!fontBase64) return; var fontUint8Array = base64ToUint8Array(fontBase64); var parsedFont = TyprInstance.parse(fontUint8Array); if (!parsedFont || parsedFont.length === 0) return; var font = parsedFont[0]; var tableJson = GM_getResourceText('Table'); if (!tableJson) return; var table; try { table = JSON.parse(tableJson); } catch(e) { return; } var match = {}; for (var i = 19968; i < 40870; i++) { var glyph = TyprInstance.U.codeToGlyph(font, i); if (!glyph) continue; var path = TyprInstance.U.glyphToPath(font, glyph); if (!path) continue; var pathStr = JSON.stringify(path); var hash = md5Instance(pathStr); if (!hash) continue; var hashKey = hash.slice(24); var realChar = table[hashKey]; if (realChar !== undefined && realChar !== null && realChar !== 0) { match[i] = realChar; } } var matchCount = Object.keys(match).length; if (matchCount === 0) return; var $elements = $('.font-cxsecret'); if ($elements.length === 0) return; $elements.each(function() { var $el = $(this); var html = $el.html(); if (!html) return; for (var code in match) { var encryptedChar = String.fromCharCode(parseInt(code)); var realChar = String.fromCharCode(match[code]); var escapedChar = encryptedChar.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); var regex = new RegExp(escapedChar, 'g'); html = html.replace(regex, realChar); } if ($el.html() !== html) { $el.html(html); $el.removeClass('font-cxsecret'); } }); log(`✅ 字体解密完成!已还原 ${matchCount} 个字符`, 'green'); } catch(e) { log('❌ 字体解密失败: ' + e.message, 'red'); } } function base64ToUint8Array(base64) { var data = window.atob(base64); var buf = new Uint8Array(data.length); for (var i = 0; i < data.length; i++) buf[i] = data.charCodeAt(i); return buf; } // 新版悬浮窗 function showBox() { if (!setting.showBox) return; try { var topDoc = top.document; if (topDoc.querySelector('#ne-21box')) { flushLogs(); quotaInfo = getQuotaInfo(); updateQuotaDisplay(); return; } } catch(e) {} var boxHtml = `

📚 学习通助手 ₙ₁ᵗ

[F9隐藏]
🔑 API配置
📊 剩余次数: 加载中...
`; try { $(top.document.body).append(boxHtml); } catch(e) { $(document.body).append(boxHtml); } setTimeout(function() { try { var targetDoc = top.document; if (!targetDoc.querySelector('#ne-21close')) { targetDoc = document; } $('#ne-21close', targetDoc).click(function() { var $box = $('#ne-21box', targetDoc); $box.css('display', 'none'); isBoxHidden = true; }); var moreBtn = targetDoc.getElementById('moreSettingsBtn'); var moreSet = targetDoc.getElementById('moreSettings'); var visible = false; if (moreBtn) { moreBtn.onclick = function() { moreSet.style.display = visible ? 'none' : 'block'; moreBtn.textContent = visible ? '⚙️ 更多设置' : '✖️ 关闭设置'; visible = !visible; }; } var goToTkBtn = targetDoc.getElementById('goToTkBtn'); if (goToTkBtn) { goToTkBtn.onclick = function() { GM_openInTab('https://n1t.cn', { active: true }); }; } $('#saveApiKeyBtn', targetDoc).click(function() { var key = $('#apiKeyInput', targetDoc).val(); if (key && key.trim()) { var $testResult = $('#testResult', targetDoc); $testResult.html('⏳ 测试中...').css('color', '#666'); testApi(key.trim(), 0).then(function(res) { GM_setValue('api_key', key.trim()); log(`✅ API密钥已保存`, 'green'); if (res.quota_info) { updateQuotaInfo(res.quota_info); } $testResult.html('✅ 密钥有效').css('color', 'green'); $('#apiKeyInput', targetDoc).val(''); $('#apiKeyInput', targetDoc).attr('placeholder', '已设置'); setTimeout(function() { $testResult.html(''); }, 3000); }).catch(function(err) { $testResult.html('❌ 密钥无效').css('color', 'red'); log(`❌ API密钥无效`, 'red'); setTimeout(function() { $testResult.html(''); }, 3000); }); } else { log('❌ 请输入API密钥', 'red'); } }); var timeIntervalInput = targetDoc.getElementById('timeInterval'); if (timeIntervalInput) { timeIntervalInput.addEventListener('change', function(e) { var newTime = parseInt(e.target.value); if (newTime >= 1000 && newTime <= 10000) { setting.time = newTime; localStorage.setItem('GPTJsSetting.time', newTime); log(`⚙️ 答题间隔: ${newTime}ms`, 'blue'); } else { e.target.value = setting.time; } }); } var settingsList = ['sub', 'force', 'examTurn', 'goodStudent', 'alterTitle']; settingsList.forEach(function(id) { var cb = targetDoc.getElementById('GPTJsSetting.' + id); if (cb) { var newCb = cb.cloneNode(true); cb.parentNode.replaceChild(newCb, cb); var savedValue = localStorage.getItem('GPTJsSetting.' + id); newCb.checked = savedValue !== null ? savedValue === 'true' : setting[id]; newCb.addEventListener('change', function(e) { var checked = e.target.checked; var settingKey = e.target.id.replace('GPTJsSetting.', ''); setting[settingKey] = checked; localStorage.setItem(e.target.id, checked); log(`⚙️ ${settingKey} = ${checked}`, 'blue'); }); } }); var savedTime = localStorage.getItem('GPTJsSetting.time'); if (savedTime) { setting.time = parseInt(savedTime); if (timeIntervalInput) timeIntervalInput.value = setting.time; } var savedKey = getApiKey(); if (savedKey) { $('#apiKeyInput', targetDoc).attr('placeholder', '已设置'); testApi(savedKey, 0).then(function(res) { if (res.quota_info) { updateQuotaInfo(res.quota_info); } log('✅ API密钥有效', 'green'); }).catch(function(err) { GM_setValue('api_key', ''); quotaInfo = { remaining: 0, free_remaining: 0, recharge_balance: 0, today_free_usage: 0 }; saveQuotaInfo(); updateQuotaDisplay(); log('⚠️ API密钥已失效,请重新设置', 'orange'); }); } else { updateQuotaDisplay(); } $('#ne-21notice', targetDoc).html(`
💡 脚本已加载 | F9隐藏/显示 | 答题间隔${setting.time/1000}秒
`); flushLogs(); showPikaqiu(); } catch(e) { console.error('绑定事件失败:', e); } }, 100); } // ========== 页面初始化 ========== $(function() { //log('🚀 学习通助手初始化中...', 'blue'); var savedServerIndex = GM_getValue('current_server_index', 0); if (savedServerIndex >= 0 && savedServerIndex < API_SERVERS.length) { CURRENT_SERVER_INDEX = savedServerIndex; } var settingsMap = { 'sub': 'sub', 'force': 'force', 'examTurn': 'examTurn', 'goodStudent': 'goodStudent', 'alterTitle': 'alterTitle', 'time': 'time' }; for (var key in settingsMap) { var val = localStorage.getItem('GPTJsSetting.' + key); if (val !== null) { if (key === 'time') { setting[settingsMap[key]] = parseInt(val); } else { setting[settingsMap[key]] = val === 'true'; } } } $('.navshow').find('a:contains(体验新版)')[0] && $('.navshow').find('a:contains(体验新版)')[0].click(); if (setting.decrypt) { setTimeout(function() { decryptFont(); }, 1000); setTimeout(function() { if ($('.font-cxsecret').length > 0) { decryptFont(); } }, 8000); } if (_l.pathname == '/login' && setting.autoLogin) { showBox(); waitForElement('#phone').then(() => { $('#phone').val(setting.phone); $('#pwd').val(setting.password); $('#loginBtn').click(); }); } else if (_l.pathname.includes('/mycourse/studentstudy')) { showBox(); log('✅ 初始化完毕!', 'green'); } else if (_l.pathname.includes('/knowledge/cards')) { showBox(); var params = getTaskParams(); if (!params || params == '$mArg') { log('⚠️ 无任务点可处理', 'red'); if (!hasTriggeredNoTaskJump) { hasTriggeredNoTaskJump = true; log('🔄 检测到无任务点,尝试跳转到下一章节...', 'blue'); setTimeout(() => { var nextBtn = top.document.querySelector('#mainid > .prev_next.next:not(.disabled)') || top.document.querySelector('#prevNextFocusNext:not(.disabled)') || top.document.querySelector('.prev_next.next:not(.disabled)') || $('.prev_next.next:not(.disabled)')[0]; if (nextBtn && !nextBtn.disabled && !nextBtn.classList.contains('disabled')) { log('✅ 找到下一节按钮,即将跳转', 'green'); nextBtn.click(); } else { log('📚 已是最后一章,无更多章节', 'green'); } }, 2000); } return; } try { var allTasks = $.parseJSON(params)['attachments']; if (!allTasks || allTasks.length <= 0) { log('⚠️ 无任务点可处理', 'red'); if (!hasTriggeredNoTaskJump) { hasTriggeredNoTaskJump = true; setTimeout(() => { var nextBtn = top.document.querySelector('#mainid > .prev_next.next:not(.disabled)') || top.document.querySelector('#prevNextFocusNext:not(.disabled)') || top.document.querySelector('.prev_next.next:not(.disabled)') || $('.prev_next.next:not(.disabled)')[0]; if (nextBtn && !nextBtn.disabled && !nextBtn.classList.contains('disabled')) { nextBtn.click(); } }, 2000); } return; } } catch(e) { log('⚠️ 解析任务参数失败', 'red'); return; } waitForElement('.wrap .ans-cc .ans-attach-ct').then(() => { top.checkJob ? top.checkJob = () => false : true; var allTasks = $.parseJSON(params)['attachments']; _defaults = $.parseJSON(params)['defaults']; _domList = []; var pendingTasks = []; for (var i = 0; i < allTasks.length; i++) { var task = allTasks[i]; if (!isTaskCompleted(task)) { pendingTasks.push(task); } else { var taskName = task.property ? (task.property.name || task.property.title || '未知') : '未知'; log(`✅ 任务点 ${taskName} 已完成,跳过`, 'green'); } } totalMissionCount = allTasks.length; pendingMissionCount = pendingTasks.length; completedMissionCount = 0; if (pendingMissionCount === 0) { log('✅ 所有任务点已完成', 'green'); setTimeout(() => { toNext(); }, 2000); return; } log(`📋 发现 ${totalMissionCount} 个任务点,其中 ${pendingMissionCount} 个待处理`, 'green'); _mlist = []; var newDomList = []; $('.wrap .ans-cc .ans-attach-ct').each((i, t) => { if (i < allTasks.length && !isTaskCompleted(allTasks[i])) { _mlist.push(allTasks[i]); newDomList.push($(t).find('iframe')); } }); _domList = newDomList; if (_mlist.length > 0) { log(`🚀 开始处理 ${_mlist.length} 个待完成任务点`, 'green'); missionStart(); } else { log('✅ 所有任务点已完成', 'green'); setTimeout(() => { toNext(); }, 2000); } }).catch(() => { log('❌ 等待元素超时', 'red'); if (!hasTriggeredNoTaskJump) { hasTriggeredNoTaskJump = true; setTimeout(() => { toNext(); }, 2000); } }); } else if (_l.pathname.includes('/exam/test/reVersionTestStartNew')) { showBox(); waitForElement('.mark_table .whiteDiv').then(() => missonExam()); } else if (_l.pathname.includes('/mooc2/work/dowork')) { showBox(); waitForElement('.mark_table form').then(() => missonHomeWork()); } else if (_l.pathname.includes('/work/phone/doHomeWork')) { var _oldal = _w.alert; _w.alert = function(msg) { if (msg == '保存成功') return; return _oldal(msg); }; var _oldcf = _w.confirm; _w.confirm = function(msg) { if (msg.includes('确认提交') || msg.includes('未做完')) return true; return _oldcf(msg); }; } });