// ==UserScript== // @name 好好学习 天天向上 // @namespace http://tampermonkey.net/ // @version 1.02 // @description 仅供学习交流使用 // @author ScriptCat // @match *://*.chaoxing.com/* // @match *://*.chaoxing.cn/* // @run-at document-idle // ==/UserScript== (function() { 'use strict'; if (window.chaoxingHelperRunning) return; window.chaoxingHelperRunning = true; var url = ''; var chapterId = ''; var arrayEchelon = []; var dealEvent = new Event("redeal", { bubbles: false, cancelable: false }); var testArrayEchelon = []; var testDealEvent = new Event("testRedeal", { bubbles: false, cancelable: false }); var testDom = null; var testBtnDocument = null; var testTasks = []; var config = { playbackRate: 1.0, autoNext: true, autoAnswer: true, debugMode: false, ifReview: 0 }; var ifTest = 'take'; var testType = 'submit'; var taskInterval = 6000; var isMainInstance = false; function log(m) { console.log(m); } function hookHidden() { try { Object.defineProperty(document, 'hidden', { get: () => false, configurable: true }); } catch(e) {} try { Object.defineProperty(document, 'visibilityState', { get: () => 'visible', configurable: true }); } catch(e) {} var origAdd = document.addEventListener; document.addEventListener = function(type, listener, options) { if (type === 'visibilitychange' || type === 'webkitvisibilitychange') return; return origAdd.call(this, type, listener, options); }; } function hookVideoPlay() { var origPlay = HTMLVideoElement.prototype.play; HTMLVideoElement.prototype.play = function() { this.muted = true; this.playbackRate = config.playbackRate; return origPlay.call(this).catch(function(){}); }; var origPause = HTMLVideoElement.prototype.pause; HTMLVideoElement.prototype.pause = function() { if (!this.ended) { log('Prevented video pause'); return; } return origPause.call(this); }; } function getIframesType(arrayAns) { return Array.from(arrayAns).map(ans => { const iframe = ans.querySelector("iframe"); const jsonStr = iframe?.getAttribute("data"); let type = null; if (!jsonStr) { const src = iframe?.getAttribute("src"); if (src) { if (src.includes('work') || src.includes('exam') || src.includes('test') || src.includes('quiz') || src.includes('homework')) { type = "workA"; } else if (src.includes('video') || src.includes('.mp4')) { type = ".mp4"; } else if (src.includes('.pdf') || src.includes('.ppt')) { type = ".pdf"; } } } else { try { const json = JSON.parse(jsonStr); if (json && json.type) { type = json.type; } else if (json && json.worktype) { type = json.worktype; } else if (json && json.resourceType) { type = json.resourceType; } } catch (error) {} } if (!type) { const className = ans.className || ''; if (className.includes('work') || className.includes('exam') || className.includes('test')) { type = "workA"; } } if (type) { log("检测到任务类型: " + type); } return type; }).filter(type => type !== null); } function getAllIframesDocument(arrayAns) { return Array.from(arrayAns).map(ans => { var iframe = ans.querySelector('iframe'); return iframe?.contentWindow?.document; }).filter(doc => doc !== undefined && doc !== null); } const handlerMap = { ".mp4": videoHandler, ".wmv": videoHandler, ".avi": videoHandler, ".mkv": videoHandler, ".flv": videoHandler, ".mov": videoHandler, ".doc": pptxHandler, ".docx": pptxHandler, ".pptx": pptxHandler, ".pdf": pptxHandler, ".ppt": pptxHandler, ".mp3": audioHandler, ".wav": audioHandler, "workA": testHandler, "workB": testHandler, "workC": testHandler, "workD": testHandler, "homework": testHandler, "exam": testHandler, "test": testHandler, "quiz": testHandler }; function distributeAns(arrayType, arrayDocument) { return arrayType.map((type, index) => { var handler = handlerMap[type] || ignoreAns; return { document: arrayDocument[index], handler, type }; }); } function dealSingleAns(singleAns) { if (singleAns && singleAns.handler && typeof singleAns.handler === 'function') { singleAns.handler(singleAns.document); } else { document.dispatchEvent(dealEvent); } } function videoHandler(idocument) { log("处理视频任务中..."); var video = idocument.querySelector("video"); var videoPlayButton = idocument.querySelector(".vjs-big-play-button"); var modalDialog = idocument.querySelector(".vjs-modal-dialog-content"); var closeButton = idocument.querySelector(".vjs-done-button"); if (!video || !videoPlayButton) { var iframes = idocument.querySelectorAll("iframe"); for (var i = 0; i < iframes.length; i++) { try { var innerDoc = iframes[i].contentDocument || iframes[i].contentWindow.document; video = innerDoc.querySelector("video"); videoPlayButton = innerDoc.querySelector(".vjs-big-play-button"); modalDialog = innerDoc.querySelector(".vjs-modal-dialog-content"); closeButton = innerDoc.querySelector(".vjs-done-button"); if (video && videoPlayButton) break; } catch(e) {} } } if (!video || !videoPlayButton) { log("没有找到视频或播放按钮,3s后将刷新页面"); setTimeout(function() { location.reload(); }, 3000); return; } var playVideo = function() { if (video && typeof video.play === 'function') { video.muted = true; video.play().catch(function(error) { console.error('视频播放失败:', error); log("视频播放失败,尝试点击播放按钮"); videoPlayButton.click(); }); } else { log("视频播放失败,尝试点击播放按钮"); videoPlayButton.click(); } }; var clickPlayVideo = function() { if (videoPlayButton && typeof videoPlayButton.click === 'function') { videoPlayButton.click(); } else { video.muted = true; video.play().catch(function(error) { console.error('视频播放失败:', error); videoPlayButton.click(); }); } }; var closeModalDialog = function() { if (modalDialog && closeButton && modalDialog.getAttribute("aria-hidden") !== "true") { setTimeout(function() { closeButton.click(); }, 2000); } }; var handlePause = function() { if (video.ended) return; clickPlayVideo(); closeModalDialog(); }; video.addEventListener("pause", handlePause); video.addEventListener("ended", function() { log("视频任务已完成"); video.removeEventListener("pause", handlePause); document.dispatchEvent(dealEvent); }, { once: true }); setTimeout(function() { if (video.paused && !video.ended) { playVideo(); log('由于程序出错未自动播放,现重新模拟点击播放按钮...'); } }, 10000); playVideo(); } function audioHandler(idocument) { log("处理音频任务中..."); const audio = idocument.querySelector("audio"); const audioPlayButton = idocument.querySelector(".vjs-play-control.vjs-control.vjs-button"); if (!audio) { document.dispatchEvent(dealEvent); return; } audioPlayButton?.click(); audio.addEventListener("ended", () => { log("音频任务已完成"); document.dispatchEvent(dealEvent); }, { once: true }); audio.addEventListener("pause", () => { audioPlayButton?.click(); }); } function pptxHandler(idocument) { log("处理 PPT/PDF 任务中..."); const iframe = idocument.querySelector("iframe"); if (!iframe) { console.warn("未找到嵌入的 iframe 元素。"); document.dispatchEvent(dealEvent); return; } const sDocument = iframe.contentWindow?.document; if (!sDocument) { console.warn("无法获取 PPT/PDF 的文档内容。"); document.dispatchEvent(dealEvent); return; } let finalHeight = sDocument.documentElement.scrollHeight; let currentHeight = 0; const scrollStep = 5; const maxHeight = finalHeight; function smoothScroll() { finalHeight = sDocument.documentElement.scrollHeight; if (currentHeight >= maxHeight) { log("PPT/PDF任务已完成"); document.dispatchEvent(dealEvent); return; } currentHeight += scrollStep; sDocument.defaultView.scrollTo(0, currentHeight); requestAnimationFrame(smoothScroll); } smoothScroll(); } function testHandler(idocument) { testDom = idocument; log("处理章节测试任务中..."); if (ifTest == 'take') { var retryCount = 0; var maxRetries = 5; function tryFindQuestions() { var iframe = idocument.querySelector("iframe"); if (iframe) { var sDocument = iframe.contentWindow?.document; if (sDocument) { var form = sDocument.querySelector("form"); testBtnDocument = sDocument.querySelector(".ZY_sub"); if (form) { var testTemps = Array.from(form.querySelectorAll('.singleQuesId, .newTestType')); testTasks = testTemps.map(function(temp) { return { document: temp, data: temp.getAttribute('data'), class: temp.getAttribute('class'), question: removeNewlines(temp.innerText), type: extractText(temp.innerText) } }).filter(function(item) { return item.class == "singleQuesId" }); if (testTasks.length > 0) { testArrayEchelon = distributeTest(testTasks); document.dispatchEvent(testDealEvent); return; } } } } retryCount++; if (retryCount < maxRetries) { log("未找到测试内容,等待重试 (" + retryCount + "/" + maxRetries + ")"); setTimeout(tryFindQuestions, 2000); } else { log("无法找到测试内容,跳过"); setTimeout(function() { document.dispatchEvent(dealEvent); }, 1000); } } tryFindQuestions(); } else if (ifTest == 'skip') { setTimeout(function() { log("根据配置选项,跳过章节测试"); document.dispatchEvent(dealEvent); }, 1000); } } function choiceHandler(idocument, testObj) { log("处理" + testObj.type + "任务中..."); var currentIndex = testTasks.findIndex(function(t) { return t.data === testObj.data }); log("第 " + (currentIndex + 1) + " 题: " + testObj.question.substring(0, 50) + "..."); // 查找选项 - 从题目元素中查找 li var options = Array.from(idocument.querySelectorAll('li')); log("找到选项数量: " + options.length); if (options.length > 0) { var randomIndex = Math.floor(Math.random() * options.length); var option = options[randomIndex]; try { option.click(); log("第 " + (currentIndex + 1) + " 题选择选项 " + String.fromCharCode(65 + randomIndex)); // 更新状态 var currentTestTask = testTasks.find(function(task) { return task.data == testObj.data }); if (currentTestTask) { currentTestTask.status = true; } } catch(e) { log("点击选项失败: " + e); } } else { log("未找到选项,忽略该题"); var currentTestTask = testTasks.find(function(task) { return task.data == testObj.data }); if (currentTestTask) { currentTestTask.status = false; } } setTimeout(function() { document.dispatchEvent(testDealEvent); }, 1000); } function tryClickOptions(doc, questionIndex) { var allClickable = doc?.querySelectorAll('span, label, div, td'); if (allClickable) { var optionPattern = /^[\s]*[A-D][..、)\s]/; var foundCount = 0; var maxOptions = 2; allClickable.forEach(function(el) { if (foundCount >= maxOptions) return; var text = el.textContent || ''; if (optionPattern.test(text)) { try { el.click(); foundCount++; log('点击选项: ' + text.trim().substring(0, 10)); } catch(e) {} } }); } } function removeNewlines(str) { return str.replace(/\n/g, ''); } function extractText(str) { var match = str.match(/【(.*?)】/); return match ? match[1] : null; } function handleWorkDirectly() { console.log('=== 直接处理答题页面 ==='); console.log('当前文档元素数量:', document.querySelectorAll('*').length); console.log('查找form:', document.querySelector('form')); console.log('查找iframe:', document.querySelector('iframe')); var retryCount = 0; var maxRetries = 15; var checkInterval = setInterval(function() { retryCount++; console.log('尝试查找答题内容 (' + retryCount + '/' + maxRetries + ')'); var workDoc = document; var form = workDoc.querySelector("form"); var iframe = workDoc.querySelector("iframe"); if (iframe) { try { var innerDoc = iframe.contentWindow?.document; if (innerDoc && innerDoc.querySelector("form")) { form = innerDoc.querySelector("form"); workDoc = innerDoc; console.log('使用iframe内部文档'); } } catch(e) { console.log('无法访问iframe:', e.message); } } if (form) { var questions = Array.from(form.querySelectorAll('.singleQuesId')); console.log('找到题目数量:', questions.length); if (questions.length > 0) { clearInterval(checkInterval); var answered = 0; questions.forEach(function(question) { var options = Array.from(question.querySelectorAll('li')); console.log('题目选项:', options.length); if (options.length > 0) { var randomIndex = Math.floor(Math.random() * options.length); try { options[randomIndex].click(); answered++; } catch(e) { console.log('点击选项失败:', e.message); } } }); console.log('共答题 ' + answered + '/' + questions.length + ' 题'); if (answered > 0) { setTimeout(function() { var subContainer = form.querySelector('.ZY_sub') || workDoc.querySelector('.ZY_sub'); console.log('按钮容器:', subContainer); if (subContainer) { var submitBtn = subContainer.querySelector('.btnSubmit'); var saveBtn = subContainer.querySelector('.btnSave'); console.log('提交按钮:', submitBtn, '保存按钮:', saveBtn); if (submitBtn) { submitBtn.click(); console.log('点击提交按钮'); } else if (saveBtn) { saveBtn.click(); console.log('点击保存按钮'); } } }, 2000); } return; } } if (retryCount >= maxRetries) { clearInterval(checkInterval); console.log('无法找到答题内容,已放弃'); } }, 2000); } function ignoreAns(doc) { log('忽略未知任务类型'); setTimeout(function() { document.dispatchEvent(dealEvent); }, 2000); } const handlerTestMap = { "单选题": choiceHandler, "多选题": choiceHandler, "判断题": choiceHandler }; function distributeTest(arrayType) { return arrayType.map(function(item) { var handler = handlerTestMap[item.type] || ignoreTest; return { document: item.document, handler: handler, testObj: item }; }); } function dealSingleTest(singleAns) { if (singleAns && singleAns.handler && typeof singleAns.handler === 'function') { singleAns.handler(singleAns.document, singleAns.testObj); } else { document.dispatchEvent(testDealEvent); } } function ignoreTest() { log("无法处理, 忽略该章节测试题"); setTimeout(function() { document.dispatchEvent(testDealEvent); }, 1000); } function skipChapter() { log("跳过章节"); var chapterNext = window.top.document.querySelector("#prevNextFocusNext"); if (chapterNext) { chapterNext.click(); } else { log("未找到 #prevNextFocusNext 元素"); } setTimeout(function() { var tip = document.querySelector(".maskDiv.jobFinishTip.maskFadeOut"); if (tip) { var tipNextChapter = document.querySelector(".jb_btn.jb_btn_92.fr.fs14.nextChapter"); if (tipNextChapter) { tipNextChapter.click(); } } else { log("未找到完成提示或下一章节按钮"); } }, taskInterval); } function dealAnsEchelon(echelonArray) { var remainingTasks = echelonArray.length; log(`待处理任务数量为: ${remainingTasks}`); if (remainingTasks === 0) { var unfinishedTasks = document.querySelectorAll('.ans-attach-ct:not(.ans-job-finished)'); if (unfinishedTasks.length > 0) { log(`检测到还有 ${unfinishedTasks.length} 个未完成任务,重新初始化任务队列`); initAll(); return; } stopProgressMonitor(); log('该章节任务已处理完成,即将跳转下一章节'); if (config.autoNext) { setTimeout(function() { skipChapter(); }, 3000); } return; } var nextTask = echelonArray.shift(); try { dealSingleAns(nextTask); } catch (error) { log('处理任务时发生错误,继续处理下一个任务'); dealAnsEchelon(echelonArray); } } function dealTestEchelon(testEchelon) { var remainingTasks = testEchelon.length; log("待处理章节测试任务数量为: " + remainingTasks); if (remainingTasks === 0) { var test_process = getTrueStatusPercentage(testTasks); log("章节测试任务完成度: " + test_process + "%"); if (!testBtnDocument) { var iframe = testDom?.querySelector("iframe"); if (iframe) { var sDocument = iframe.contentWindow?.document; if (sDocument) { testBtnDocument = sDocument.querySelector(".ZY_sub"); } } } setTimeout(function() { if (testBtnDocument) { var save_btn = testBtnDocument.querySelector('.btnSave'); var submit_btn = testBtnDocument.querySelector('.btnSubmit'); if (test_process == 100) { log('章节测试任务已全部完成'); if (testType == 'submit') { if (submit_btn) { submit_btn.click(); log('章节测试答案已提交'); setTimeout(function() { try { var mask_div = window.top.document.querySelector('.maskDiv'); if (mask_div) { var pop_ok = mask_div.querySelector('#popok'); if (pop_ok) { pop_ok.click(); log('点击确认提交按钮'); } } } catch(e) {} }, 1000); } else { log('未找到提交按钮'); } } else { if (save_btn) { save_btn.click(); log('章节测试答案已暂时保存'); } else { log('未找到保存按钮'); } } } else { log("章节测试任务完成度不足100%,将暂时保存"); if (save_btn) { save_btn.click(); log('章节测试答案已暂时保存'); } else { log('未找到保存按钮'); } } } else { log('未找到章节测试按钮容器'); } setTimeout(function() { log('章节测试任务已完成'); document.dispatchEvent(dealEvent); }, 5000); }, 1000); return; } var nextTask = testEchelon.shift(); try { dealSingleTest(nextTask); } catch (error) { log('处理章节测试任务时发生错误,继续下一个'); dealTestEchelon(testEchelon); } } function getTrueStatusPercentage(arr) { var trueCount = arr.filter(function(item) { return item.status === true; }).length; return (trueCount / arr.length) * 100; } function initAll() { autoSkipDone = false; isMainInstance = true; log('正在获取当前页面的任务...'); console.log('开始查找任务元素...'); var arrayAns = document.querySelectorAll(".ans-attach-ct"); console.log('找到 .ans-attach-ct 元素:', arrayAns.length); if (arrayAns.length === 0) { arrayAns = document.querySelectorAll(".ans-job-ct"); console.log('找到 .ans-job-ct 元素:', arrayAns.length); } if (arrayAns.length === 0) { arrayAns = document.querySelectorAll(".chapter-item"); console.log('找到 .chapter-item 元素:', arrayAns.length); } if (arrayAns.length === 0) { arrayAns = document.querySelectorAll('[class*="ans"], [class*="task"], [class*="chapter"]'); console.log('找到包含 ans/task/chapter 的元素:', arrayAns.length); } var arrayAnsAll = arrayAns; var finishedTasks = document.querySelectorAll('.ans-attach-ct.ans-job-finished, .ans-job-finished'); var unfinishedTasks = document.querySelectorAll('.ans-attach-ct:not(.ans-job-finished), .ans-job-ct:not(.ans-job-finished)'); var progress = arrayAnsAll.length > 0 ? Math.round((finishedTasks.length / arrayAnsAll.length) * 100) + '%' : '--'; log(`当前页面任务数量为: ${arrayAnsAll.length}`); console.log('已完成任务:', finishedTasks.length, '未完成任务:', unfinishedTasks.length); var filteredArrayAns = config.ifReview == 1 ? arrayAns : document.querySelectorAll('.ans-attach-ct:not(.ans-job-finished), .ans-job-ct:not(.ans-job-finished)'); var taskCount = filteredArrayAns.length; console.log('待处理任务数量:', taskCount); if (filteredArrayAns && taskCount > 0) { try { console.log('开始获取任务类型...'); var arrayType = getIframesType(filteredArrayAns); console.log('任务类型:', arrayType); var arrayDocument = getAllIframesDocument(filteredArrayAns); console.log('获取到文档数量:', arrayDocument.length); arrayEchelon = distributeAns(arrayType, arrayDocument); console.log('任务队列:', arrayEchelon); log(`当前页面待办任务数量为: ${arrayEchelon.length}`); startProgressMonitor(); document.dispatchEvent(dealEvent); } catch (error) { log('初始化过程中发生错误: ' + error); console.error('错误详情:', error); } } else { log('当前页面没有可处理的任务,直接跳过章节'); console.log('尝试查找所有iframe...'); var allIframes = document.querySelectorAll('iframe'); console.log('页面中iframe数量:', allIframes.length); allIframes.forEach(function(iframe, index) { console.log('iframe ' + index + ':', iframe.src, iframe.getAttribute('data')); }); if (config.autoNext) { skipChapter(); } } } document.addEventListener("redeal", function() { if (!isMainInstance) return; setTimeout(function() { dealAnsEchelon(arrayEchelon); }, 1500); }); document.addEventListener("testRedeal", function() { if (!isMainInstance) return; setTimeout(function() { dealTestEchelon(testArrayEchelon); }, 1000); }); var uiCreated = false; function buildUI() { if (window !== window.top) return; if (uiCreated) return; document.querySelectorAll('#cxh_panel, #cxh_toggle').forEach(el => el.remove()); var panel = document.createElement('div'); panel.id = 'cxh_panel'; panel.innerHTML = `
好好学习 天天向上
仅供学习参考使用
赞赏码
你的打赏是我前进的动力欢迎哥哥姐姐们投来的三瓜俩枣
`; panel.style.cssText = 'position:fixed;left:20px;bottom:20px;background:#fff;border-radius:12px;box-shadow:0 4px 20px rgba(0,0,0,0.2);padding:10px;width:270px;z-index:999999;font-family:system-ui,sans-serif;'; document.body.appendChild(panel); var toggleBtn = document.createElement('button'); toggleBtn.id = 'cxh_toggle'; toggleBtn.textContent = 'Dr'; toggleBtn.style.cssText = 'position:fixed;bottom:20px;left:20px;width:45px;height:45px;border-radius:50%;background:#4CAF50;border:none;color:white;font-size:20px;cursor:pointer;z-index:999998;display:none;'; document.body.appendChild(toggleBtn); document.getElementById('cxh_close').onclick = function() { panel.style.display = 'none'; toggleBtn.style.display = 'block'; }; document.getElementById('cxh_next').onchange = function(e) { config.autoNext = e.target.checked; }; document.getElementById('cxh_ans').onchange = function(e) { config.autoAnswer = e.target.checked; }; toggleBtn.onclick = function() { panel.style.display = 'block'; this.style.display = 'none'; }; uiCreated = true; } function updateStatus() {} var progressMonitor = null; var autoSkipDone = false; function formatTime(seconds) { var m = Math.floor(seconds / 60); var s = Math.floor(seconds % 60); return m + ':' + (s < 10 ? '0' : '') + s; } function startProgressMonitor() { if (progressMonitor) return; console.log('[进度] 开始任务进度监控(每30秒输出一次)'); progressMonitor = setInterval(function() { var videoFound = false; var docs = [document]; var iframes = document.querySelectorAll('iframe'); for (var fi = 0; fi < iframes.length; fi++) { try { if (iframes[fi].contentDocument) { docs.push(iframes[fi].contentDocument); } } catch(e) {} } for (var di = 0; di < docs.length; di++) { var vs = docs[di].querySelectorAll('video'); for (var vi = 0; vi < vs.length; vi++) { var v = vs[vi]; if (v.duration && v.duration > 0 && !v.ended) { var cur = Math.floor(v.currentTime); var tot = Math.floor(v.duration); var rem = tot - cur; var pct = tot > 0 ? ((cur / tot) * 100).toFixed(1) : '0.0'; console.log('[进度] 视频播放: ' + formatTime(cur) + ' / ' + formatTime(tot) + ' (' + pct + '%) 剩余 ' + formatTime(rem)); var at = document.querySelectorAll('.ans-attach-ct, .ans-job-ct, .chapter-item'); var dt = document.querySelectorAll('.ans-attach-ct.ans-job-finished, .ans-job-ct.ans-job-finished'); if (at.length > 0) { var taskPct = ((dt.length / at.length) * 100).toFixed(0); console.log('[进度] 章节任务完成: ' + dt.length + '/' + at.length + ' (' + taskPct + '%)'); if (dt.length === at.length && !autoSkipDone) { autoSkipDone = true; console.log('[进度] 当前章节所有任务已全部完成,准备自动跳转下一章'); stopProgressMonitor(); setTimeout(function() { skipChapter(); }, 3000); } } videoFound = true; break; } } if (videoFound) break; } if (videoFound) return; if (testTasks.length > 0) { var completed = testTasks.filter(function(t) { return t.status === true; }).length; var total = testTasks.length; var curQ = ''; for (var j = 0; j < testTasks.length; j++) { if (!testTasks[j].status) { curQ = '第 ' + (j + 1) + ' 题'; break; } } if (!curQ) curQ = '全部完成'; var pct = total > 0 ? ((completed / total) * 100).toFixed(0) : '0'; console.log('[进度] 章节测试: ' + completed + '/' + total + ' (' + pct + '%) 当前: ' + curQ + ' 剩余: ' + (total - completed) + ' 题'); return; } if (arrayEchelon.length > 0) { console.log('[进度] 待处理任务队列: ' + arrayEchelon.length + ' 个'); return; } var allTasks = document.querySelectorAll('.ans-attach-ct, .ans-job-ct, .chapter-item'); var doneTasks = document.querySelectorAll('.ans-attach-ct.ans-job-finished, .ans-job-ct.ans-job-finished'); if (allTasks.length > 0) { var pct = ((doneTasks.length / allTasks.length) * 100).toFixed(0); console.log('[进度] 章节任务完成: ' + doneTasks.length + '/' + allTasks.length + ' (' + pct + '%)'); if (doneTasks.length === allTasks.length) { console.log('[进度] 当前章节所有任务已全部完成,准备自动跳转下一章'); if (!autoSkipDone) { autoSkipDone = true; stopProgressMonitor(); setTimeout(function() { skipChapter(); }, 3000); } } } }, 30000); } function stopProgressMonitor() { if (progressMonitor) { clearInterval(progressMonitor); progressMonitor = null; console.log('[进度] 任务进度监控已停止'); } } function start() { console.log('=== 学习通刷课脚本启动 ==='); console.log('当前URL:', window.location.href); console.log('是否在顶层:', window === window.top); console.log('路径:', location.pathname); hookHidden(); hookVideoPlay(); // 在 /mooc-ans/knowledge/cards 下执行 initAll(刷1的方式) if (location.pathname == '/mooc-ans/knowledge/cards') { console.log('在知识卡片页面,等待5秒后初始化任务'); if (window === window.top) { buildUI(); } setTimeout(function() { initAll(); }, 5000); } // 在顶层页面 studentstudy 中构建UI else if (location.pathname == '/mycourse/studentstudy') { if (window === window.top) { buildUI(); } } // 直接处理答题页面 else if (location.pathname == '/ananas/modules/work/index.html' || location.pathname == '/mooc-ans/work/doHomeWorkNew') { console.log('直接在答题页面处理'); handleWorkDirectly(); } } function waitForReady() { if (document.readyState === 'complete' || document.readyState === 'interactive') { start(); } else { console.log('等待页面加载...'); document.addEventListener('DOMContentLoaded', start); window.addEventListener('load', function() { if (!window.chaoxingHelperRunning) { console.log('页面加载完成,启动脚本'); start(); } }); } } waitForReady(); })();