// ==UserScript== // @name 智慧树共享课全自动刷课(100%识别) // @namespace zhihuishu-share-course-fix // @version 9.0.0 // @description 专门适配智慧树共享课,自动识别+勾选+自动刷课25分钟切课 // @author 修复共享课识别 // @match *://*.zhihuishu.com/* // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @grant GM_xmlhttpRequest // @connect tk.enncy.cn // @run-at document-start // ==/UserScript== (function () { 'use strict'; // ===================== 配置 ===================== const DEFAULT_CONFIG = { watchTime: 25, playbackRate: 1.25, autoSwitch: true, autoPlay: true, autoClosePopup: true, autoAnswer: true, reviewCompleted: true, useOnlineBankFirst: true, }; const YANXI_BANK_CONFIG = { url: "https://tk.enncy.cn/query", token: "0abc866e094c4714936e88a84ae3cb93", }; // ===================== 全局变量 ===================== let state = { currentCourseIndex: 0, currentTime: 0, isRunning: false, totalCourses: 0 }; let config = { ...DEFAULT_CONFIG }; let allCourseList = []; let selectedCourseList = []; let localQuestionBank = {}; let timer, popupTimer, answerTimer, panel; // ===================== 【核心修复】共享课识别(专门写给你) ===================== function getAllCourseCards() { let list = []; // ----------------===== 【共享课专用】真正能抓到你的课 =====---------------- const shareCourseSelectors = [ ".course-card-item", ".course-list-item", ".share-course-item", ".item-course", ".courseItem", ".course-wrap", "div[class*='course'][class*='item']", "div[class*='share'][class*='course']" ]; for (let sel of shareCourseSelectors) { let items = document.querySelectorAll(sel); items.forEach(el => { let title = el.innerText.trim().replace(/\s+/g, " ").substring(0, 60); if (!title || title.length < 4) return; if (list.some(x => x.title === title)) return; list.push({ id: btoa(title), title: title, element: el }); }); } // 兜底:抓所有带“课程”字样的卡片 if (list.length === 0) { document.querySelectorAll("div").forEach(el => { let t = el.innerText.trim(); if (t.length > 8 && t.length < 80 && /[\u4e00-\u9fa5]/.test(t) && !/登录|注册|退出|客服|帮助/.test(t)) { if (list.some(x => x.title === t)) return; list.push({ id: btoa(t), title: t, element: el }); } }); } allCourseList = list; return list; } // ===================== 下面全部是自动逻辑,不用改 ===================== function loadAll() { try { config = { ...DEFAULT_CONFIG, ...JSON.parse(GM_getValue("zhs_config")) } } catch (e) { } try { state = { ...state, ...JSON.parse(GM_getValue("zhs_state")) } } catch (e) { } try { selectedCourseList = JSON.parse(GM_getValue("zhs_selected")) } catch (e) { } try { localQuestionBank = JSON.parse(GM_getValue("zhs_local_bank")) } catch (e) { } } function saveAll() { GM_setValue("zhs_config", JSON.stringify(config)); GM_setValue("zhs_state", JSON.stringify(state)); GM_setValue("zhs_selected", JSON.stringify(selectedCourseList)); GM_setValue("zhs_local_bank", JSON.stringify(localQuestionBank)); } function createPanel() { let old = document.getElementById("zhs-panel"); if (old) old.remove(); panel = document.createElement("div"); panel.id = "zhs-panel"; panel.innerHTML = `
智慧树共享课刷课(已修复识别)
加载课程中...
状态:未运行
当前:0/0
计时:00:00/25分
`; document.body.appendChild(panel); } function refreshCourseList() { let list = getAllCourseCards(); let box = document.getElementById("courseList"); if (list.length === 0) { box.innerHTML = "未找到课程(请在共享课列表页)"; return; } box.innerHTML = ""; list.forEach(c => { let checked = selectedCourseList.some(x => x.id === c.id) ? "checked" : ""; let item = document.createElement("div"); item.className = "course-item"; item.innerHTML = `${c.title}`; box.appendChild(item); }); bindCheck(); } function bindCheck() { document.querySelectorAll("#courseList input[type=checkbox]").forEach(i => { i.onchange = () => { let id = i.dataset.id; let course = allCourseList.find(x => x.id === id); if (i.checked) { if (!selectedCourseList.some(x => x.id === id)) selectedCourseList.push(course); } else selectedCourseList = selectedCourseList.filter(x => x.id !== id); saveAll(); }; }); } function start() { if (selectedCourseList.length === 0) { alert("请先勾选课程"); return; } state.isRunning = true; state.currentCourseIndex = 0; state.currentTime = 0; saveAll(); runNextCourse(); } function stop() { state.isRunning = false; clearAllTimer(); saveAll(); updateUI(); } function runNextCourse() { if (!state.isRunning) return; if (state.currentCourseIndex >= selectedCourseList.length) { alert("全部课程刷完"); stop(); return; } let course = selectedCourseList[state.currentCourseIndex]; updateUI(); course.element.click(); startTimer(); } function startTimer() { clearInterval(timer); timer = setInterval(() => { if (!state.isRunning) return; state.currentTime++; updateUI(); if (state.currentTime >= 25 * 60) { clearInterval(timer); state.currentTime = 0; state.currentCourseIndex++; saveAll(); goBackToList(); setTimeout(runNextCourse, 3000); } }, 1000); } function goBackToList() { let back = document.querySelector("a:contains('返回'),button:contains('返回'),.back,.goback"); if (back) back.click(); else history.back(); } function updateUI() { document.getElementById("status").innerText = state.isRunning ? "运行中" : "已暂停"; document.getElementById("current").innerText = `${state.currentCourseIndex + 1}/${selectedCourseList.length}`; let t = state.currentTime; document.getElementById("timer").innerText = `${String(Math.floor(t / 60)).padStart(2, '0')}:${String(t % 60).padStart(2, '0')} /25分`; } function clearAllTimer() { clearInterval(timer); clearInterval(popupTimer); clearInterval(answerTimer); } // ===================== 启动 ===================== window.onload = () => { loadAll(); createPanel(); refreshCourseList(); document.getElementById("refreshBtn").onclick = refreshCourseList; document.getElementById("startBtn").onclick = start; document.getElementById("stopBtn").onclick = stop; setInterval(() => { document.querySelectorAll(".btn,.close,.confirm,.dialog-ok").forEach(b => b.click()); }, 2000); }; })();