// ==UserScript== // @name 生态环境云课堂自动学习助手v2.8 // @namespace http://onlinelearning.21tb.com/ // @version 2.8 // @description 自动关所有弹窗(含消息通知),自动选未学习必修课程,自动点下一节,自动答题,静音后台运行 // @author study_bot // @match *://onlinelearning.21tb.com/* // @grant none // @run-at document-idle // @tag 教育,学习,自动化 // @license MIT // ==/UserScript== (function() { 'use strict'; const CHECK_INTERVAL = 4000; const ACTION_COOLDOWN = 10000; let lastActionTime = 0; function log(msg) { try { console.log(`[自动学习v2.8] ${new Date().toLocaleTimeString()} ${msg}`); } catch(e) {} } // 1. 关闭所有弹窗(含消息、通知、提示) function closeAllPopups() { try { // 所有关闭按钮 document.querySelectorAll('.el-dialog__close, .el-message-box__close, .close-btn, .el-icon-close, .el-dialog__headerbtn').forEach(btn => { try { btn.click(); } catch(e){} }); // 点空白处关闭弹窗 document.querySelectorAll('.el-dialog__wrapper, .v-modal').forEach(modal => { try { modal.click(); } catch(e){} }); } catch(e) {} } // 2. 视频静音自动播放 function playVideo() { try { document.querySelectorAll('video').forEach(v => { v.muted = true; v.volume = 0; v.playbackRate = 1; if (v.paused) v.play().catch(()=>{}); }); } catch(e) {} } // 3. 自动点下一节/未完成章节 function clickNextUnfinished() { const now = Date.now(); if (now - lastActionTime < ACTION_COOLDOWN) return; try { // 找绿色"下一节"按钮 const nextBtn = [...document.querySelectorAll('button, div')].find(el => el.innerText && el.innerText.trim() === '下一节' && el.offsetParent !== null ); if (nextBtn) { log('点击下一节'); nextBtn.click(); lastActionTime = now; return; } // 找橙色"未完成"章节 const unDone = [...document.querySelectorAll('span, div')].filter(el => el.innerText && el.innerText.trim() === '未完成' && el.offsetParent !== null ); for (let el of unDone) { let parent = el.parentElement; for (let i=0;i<6;i++) { if (!parent) break; if (parent.tagName === 'LI' || parent.tagName === 'A' || parent.onclick) { log('选择未完成章节'); parent.click(); lastActionTime = now; return; } parent = parent.parentElement; } } } catch(e) {} } // 4. 课程列表页自动选未学习课程 function pickNextCourse() { const now = Date.now(); if (now - lastActionTime < ACTION_COOLDOWN) return; try { // 找所有课程卡片,跳过标记"完成"的,点第一个0%/未学习的 const cards = [...document.querySelectorAll('[class*=course-item], [class*=card], .list-item')]; for (let card of cards) { const txt = card.innerText; if (txt.includes('必修') && !txt.includes('已完成') && !txt.includes('100%')) { log('点击未学习必修课程: ' + txt.slice(0,40)); card.click(); lastActionTime = now; return; } } } catch(e) {} } // 5. 自动答题 async function autoAnswer() { try { const questions = document.querySelectorAll('[class*=question]'); if (!questions.length) return; log(`检测到${questions.length}道题,开始作答`); for (let q of questions) { const opts = q.querySelectorAll('label, .option-item, .el-radio, .el-checkbox'); const unsel = [...opts].filter(o => !o.classList.contains('is-checked')); if (unsel.length) { unsel[Math.floor(Math.random()*unsel.length)].click(); await new Promise(r => setTimeout(r, 200)); } } await new Promise(r => setTimeout(r, 1000)); const allDone = [...questions].every(q => q.querySelectorAll('.is-checked').length > 0); if (allDone) { const submit = [...document.querySelectorAll('button')].find(b => b.innerText.includes('提交')); if (submit) submit.click(); } } catch(e) {} } // 6. 主循环 async function loop() { closeAllPopups(); playVideo(); // 如果在课程列表页,自动选未学课程 if (location.href.includes('course_manage_user_pc')) { pickNextCourse(); } else { // 在播放页,自动切下一节 clickNextUnfinished(); } if (document.body.innerText.includes('单选题')) await autoAnswer(); setTimeout(loop, CHECK_INTERVAL); } log('自动学习v2.8启动:自动关消息弹窗、自动选未学课程'); setTimeout(loop, 2000); })();