// ==UserScript== // @name 齐大抢课 // @namespace https://greasyfork.org/users/737539 // @version 1.0.1 // @description 仅供学习交流使用,可同时匹配多个课程代码,课程码为纯数字,例如“体育4(1234-5)”就填“412345” // @icon https://xyh.qqhru.edu.cn/favicon.ico // @author 忘忧 // @license MIT // @match http://111.43.36.164/student/courseSelect/courseSelect/index // @match http://111.43.36.164/student/teachingEvaluation/teachingEvaluation/evaluationPage // @match http://111.43.36.164/student/teachingEvaluation/teachingEvaluation/index // @match http://172.20.139.153:7700/student/teachingEvaluation/teachingEvaluation/evaluationPage // @match http://172.20.139.153:7700/student/teachingEvaluation/teachingEvaluation/index // @match https://172-20-139-153-7700.webvpn.qqhru.edu.cn/student/teachingEvaluation/teachingEvaluation/evaluationPage // @match https://172-20-139-153-7700.webvpn.qqhru.edu.cn/student/teachingEvaluation/teachingEvaluation/index // @match https://172-20-139-153-7700.webvpn.qqhru.edu.cn/student/teachingEvaluation/evaluation/index // @match http://172.20.139.153:7700/student/teachingEvaluation/evaluation/index // @match http://172.20.139.153:7700/student/courseSelect/courseSelect/index // @grant none // ==/UserScript== (function () { 'use strict'; let targetCourses = []; let matchedCourses = []; let timer = null; // 创建UI function createUI() { console.log('[初始化] 正在创建 UI...'); const uiContainer = document.createElement('div'); uiContainer.id = 'uiContainer'; uiContainer.style.position = 'absolute'; uiContainer.style.top = '10px'; uiContainer.style.right = '10px'; uiContainer.style.width = '300px'; uiContainer.style.backgroundColor = '#f4f4f4'; uiContainer.style.border = '1px solid #ccc'; uiContainer.style.padding = '10px'; uiContainer.style.zIndex = '9999'; uiContainer.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.2)'; uiContainer.innerHTML = `
暂无课程
匹配成功的课程代码
暂无课程
'; console.log('[操作成功] 当前课程列表为空'); } else { targetCourses.forEach((course, index) => { const courseItem = document.createElement('div'); courseItem.style.display = 'flex'; courseItem.style.justifyContent = 'space-between'; courseItem.style.marginBottom = '5px'; courseItem.innerHTML = ` ${course} `; courseItem.querySelector('button').addEventListener('click', (e) => { const idx = e.target.getAttribute('data-index'); targetCourses.splice(idx, 1); updateCourseList(); console.log(`[操作成功] 已删除课程代码: ${course}`); }); courseListDiv.appendChild(courseItem); }); console.log('[操作成功] 更新课程列表完成'); } } // 更新匹配成功的课程列表 function updateMatchedCourses() { console.log('[操作] 更新匹配成功的课程列表...'); const matchedCoursesDiv = document.getElementById('matchedCourses'); matchedCoursesDiv.innerHTML = ''; if (matchedCourses.length === 0) { matchedCoursesDiv.innerHTML = '匹配成功的课程代码
'; } else { matchedCourses.forEach(course => { const courseItem = document.createElement('div'); courseItem.textContent = course; matchedCoursesDiv.appendChild(courseItem); }); console.log('[操作成功] 更新匹配成功的课程列表完成'); } } // 点击提交按钮 function clickSubmitButton() { const button = document.querySelector('#submitButton'); // 在主页面上下文查找提交按钮 if (button) { console.log('[操作成功] 找到提交按钮,正在尝试使用 dispatchEvent 提交...'); const event = new MouseEvent('click', { bubbles: true, cancelable: true, view: window }); button.dispatchEvent(event); // 使用 dispatchEvent 触发事件 console.log('[操作成功] 使用 dispatchEvent 提交课程'); } else { console.warn('[警告] 未找到提交按钮,请检查选择器是否正确'); } } // 检查并选中课程 async function checkAndSelectCourses() { console.log('[操作] 开始检查课程...'); const iframeDoc = document.querySelector('#ifra')?.contentDocument; if (!iframeDoc) { console.error('[错误] 无法获取 iframe 文档'); return; } if (targetCourses.length === 0) { console.log('[操作完成] 所有课程已处理,尝试提交...'); clickSubmitButton(); stopScript(); return; } const courseCode = targetCourses[0]; // 获取第一个课程码 const rows = iframeDoc.querySelectorAll('tr'); console.log(`[调试] 正在匹配课程代码: ${courseCode},总共找到 ${rows.length} 行课程数据`); let matched = false; rows.forEach((row) => { const courseCells = row.querySelectorAll('td[rowspan]'); // 匹配所有具有 rowspan 属性的单元格 courseCells.forEach((courseCell) => { const cellText = courseCell.textContent.trim(); const cellNumber = cellText.match(/\d+/g)?.join('') || ''; console.log(`[调试] 检查单元格内容: ${cellText}, 提取的数字: ${cellNumber}`); if (cellNumber === courseCode) { matched = true; console.log(`[匹配成功] 课程代码: ${courseCode}, 单元格内容: ${cellText}`); const checkbox = row.querySelector(`input[type="checkbox"]`); if (checkbox && !checkbox.checked) { checkbox.click(); console.log(`[操作成功] 已勾选课程: ${courseCode}`); } } }); }); if (matched) { console.log(`[操作完成] 已处理课程: ${courseCode}`); matchedCourses.push(courseCode); updateMatchedCourses(); targetCourses.shift(); // 移除已处理的课程码 } else { console.warn(`[警告] 未匹配到课程代码: ${courseCode}`); } } // 启动脚本 function startScript() { console.log('[操作] 启动脚本...'); if (targetCourses.length === 0) { alert('[错误] 请先添加课程'); return; } timer = setInterval(checkAndSelectCourses, 1000); document.getElementById('startScript').disabled = true; document.getElementById('stopScript').disabled = false; console.log('[操作成功] 脚本已启动'); } // 停止脚本 function stopScript() { console.log('[操作] 停止脚本...'); clearInterval(timer); timer = null; document.getElementById('startScript').disabled = false; document.getElementById('stopScript').disabled = true; console.log('[操作成功] 脚本已停止'); } // 初始化脚本 window.addEventListener('load', createUI); })();