// ==UserScript== // @name 生态环境云课堂自动学习助手 // @namespace http://onlinelearning.21tb.com/ // @version 3.0 // @description 全国生态环境执法培训云课堂全自动学习:自动关弹窗、自动进课程、自动选未学必修、自动播放切章节、自动答完所有题提交,静音后台运行不打扰工作 // @author study_bot // @match *://onlinelearning.21tb.com/* // @grant none // @run-at document-idle // @noframes // @tag 教育,学习,自动化,网课,云课堂 // @license MIT // ==/UserScript== (function() { 'use strict'; // 配置 const CONFIG = { checkInterval: 5000, actionCooldown: 12000, maxRetries: 5, }; const state = { lastActionTime: 0, retryCount: 0, visitedCourses: new Set(JSON.parse(localStorage.getItem('visitedCourses') || '[]')), }; function log(msg) { try { console.log(`[云课堂自动学习v3.0] ${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').forEach(modal => { try { if (modal.style.display !== 'none') modal.click(); } catch(e){} }); } catch(e) {} } // 2. 视频静音自动播放 function ensureVideoPlaying() { try { document.querySelectorAll('video').forEach(v => { v.muted = true; v.volume = 0; v.playbackRate = 1; if (v.paused || v.ended) v.play().catch(()=>{}); }); } catch(e) {} } // 3. 首页自动进入我的课程 function goToMyCourses() { const now = Date.now(); if (now - state.lastActionTime < CONFIG.actionCooldown) return; try { if (location.pathname.includes('/student/index')) { const navBtn = [...document.querySelectorAll('a, div, span, .nav-item')].find(el => el.innerText && el.innerText.trim() === '我的课程' && el.offsetParent !== null ); if (navBtn) { log('首页:点击进入我的课程'); navBtn.click(); state.lastActionTime = now; } } } catch(e) {} } // 4. 课程列表页自动选择未学习必修课程 function pickNextUnfinishedCourse() { const now = Date.now(); if (now - state.lastActionTime < CONFIG.actionCooldown) return; try { if (!location.href.includes('course_manage_user_pc')) return; // 获取所有课程卡片 const cards = [...document.querySelectorAll('[class*=course-card], [class*=item-card], .list-item, .course-item')]; for (let card of cards) { const text = card.innerText || ''; // 跳过已完成的、已经点过的 if (text.includes('已完成') || text.includes('100%') || state.visitedCourses.has(text.slice(0,20))) continue; // 只选必修课 if (text.includes('必修') && !text.includes('完成')) { log('找到未学习必修课程: ' + text.split('\n')[0]); card.click(); state.visitedCourses.add(text.slice(0,20)); localStorage.setItem('visitedCourses', JSON.stringify([...state.visitedCourses])); state.lastActionTime = now; return; } } } catch(e) {} } // 5. 播放页自动切下一节/未完成章节 function switchToNextSection() { const now = Date.now(); if (now - state.lastActionTime < CONFIG.actionCooldown) return; try { if (!location.href.includes('courseLearning/play')) return; // 先找绿色"下一节"按钮 const nextBtn = [...document.querySelectorAll('button, div, .btn')].find(el => el.innerText && el.innerText.trim() === '下一节' && el.offsetParent !== null ); if (nextBtn) { log('点击下一节'); nextBtn.click(); state.lastActionTime = now; return; } // 找右侧未完成章节 const unDoneNodes = [...document.querySelectorAll('span, div')].filter(el => el.innerText && el.innerText.trim() === '未完成' && el.offsetParent !== null ); for (let el of unDoneNodes) { 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(); state.lastActionTime = now; return; } parent = parent.parentElement; } } } catch(e) {} } // 6. 自动答题(答完所有题再提交) async function autoAnswerQuiz() { try { const questions = document.querySelectorAll('[class*=question-item], [class*=topic]'); if (!questions.length) return; log(`检测到${questions.length}道测试题,开始作答`); for (let q of questions) { const options = q.querySelectorAll('label, .option, .el-radio, .el-checkbox-item'); const unselected = [...options].filter(o => !o.classList.contains('is-checked')); if (unselected.length) { unselected[Math.floor(Math.random() * unselected.length)].click(); await new Promise(r => setTimeout(r, 250)); } } await new Promise(r => setTimeout(r, 1000)); // 确认所有题都选完才提交 const allAnswered = [...questions].every(q => q.querySelectorAll('.is-checked').length > 0); if (allAnswered) { const submitBtn = [...document.querySelectorAll('button')].find(b => b.innerText.includes('提交')); if (submitBtn) { log('所有题目作答完成,提交答卷'); submitBtn.click(); state.retryCount = 0; } } } catch(e) {} } // 7. 主循环 async function mainLoop() { closeAllPopups(); ensureVideoPlaying(); goToMyCourses(); pickNextUnfinishedCourse(); switchToNextSection(); if (document.body.innerText.includes('单选题') || document.body.innerText.includes('多选题')) { await autoAnswerQuiz(); } setTimeout(mainLoop, CONFIG.checkInterval); } log('v3.0稳定版启动:自动学习所有必修课程'); setTimeout(mainLoop, 3000); })();