// ==UserScript== // @name 学习公社刷课专用 // @namespace chengfx // @version 2024-02-19 // @description 刷课专用 // @author chengfx // @match https://www.ttcdw.cn/p/course/v/v_*?itemId=*&segId=*&projectId=*&orgId=*&type=* // @match https://www.ttcdw.cn/p/uc/projectCenter/* // @icon https://www.google.com/s2/favicons?sz=64&domain=ttcdw.cn // @grant none // @license MIT // @downloadURL none // ==/UserScript== const createBroadcastChannel=(cb)=> { const broadcastChannel = new BroadcastChannel('chengfx'); broadcastChannel.onmessage = cb; return broadcastChannel; } const autoContinue = ()=>{ const modal = document.querySelector("#layui-layer1"); if(!modal || modal.style.display === 'none'){ return; } const btn = document.querySelector("#comfirmClock"); btn.click(); } const autoPlayCourse = ()=>{ const videos = document.querySelectorAll('video'); videos.forEach(v=>{ v.muted=true; v.play() }) } const findUnfinishCourseItem = ()=>{ const allCourseItems = [...document.querySelectorAll(".course-info")]; const unfinishCourseItem = allCourseItems.find(course=>course.querySelector('.four').innerText !== '100%'); return unfinishCourseItem; } const autoJumpCourse = (unfinishCourseItem)=>{ if(!unfinishCourseItem){ console.info("allFinish") return false; }else{ unfinishCourseItem.children[0]?.click(); setTimeout(autoPlayCourse,1000) return true; } } const nextModule = ()=>{ const allModules = [...document.querySelectorAll(".item-col")]; const activeIndex = allModules.findIndex(m=>!!m.querySelector('.is-active')); console.log(allModules[activeIndex+1]) allModules[activeIndex+1]?.querySelector('.el-collapse-item__header')?.click();; } const openUnfinishCourse = ()=>{ const unfinishCourse = [...document.querySelectorAll(".el-table__row")].find((e)=>e.querySelector(".course_num").innerText !== "课程:100%"); if(!unfinishCourse){ return false; } const learnBtn = unfinishCourse.querySelector(".to-study"); learnBtn.click(); return true; } (function() { 'use strict'; const init = async ()=>{ console.info("success") const isPlayPage = location.href.startsWith("https://www.ttcdw.cn/p/course"); if(isPlayPage){ const bc = createBroadcastChannel((msg)=>{ console.log(msg); }); console.log("im play page"); let lastCourse = null; setInterval(autoContinue,1000); setInterval(()=>{ const course = findUnfinishCourseItem(); if(!course){ bc.postMessage({cmd:"next"}); window.close(); return; } if(lastCourse === course){ return; } autoJumpCourse(course); lastCourse = course; },1000) }else{ console.log("im not play page"); while(!openUnfinishCourse()){ nextModule() await new Promise((res,rej)=>{setTimeout(res,1000)}); } const bc = createBroadcastChannel((msg)=>{ switch(msg.data.cmd){ case 'next':{ console.log("next"); location.reload(); break; } } }); bc.postMessage({a:1}) } } setTimeout(init,2000) })();