重庆医科大学自动评教脚本

自动将评教页面前7个选项选择为"A 好"

目前為 2025-06-25 提交的版本,檢視 最新版本

// ==UserScript==
// @name         重庆医科大学自动评教脚本
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  自动将评教页面前7个选项选择为"A 好"
// @author       一位学长
// @match        https://jiaowu.cqmu.edu.cn/*
// @grant        none
// @run-at       document-end
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';
    
    // 主函数
    function autoEvaluate() {
        // 检测是否在评教页面
        const evaluateContent = document.getElementById('courseEvaluateContent');
        if (!evaluateContent) {
            return;
        }
        
        console.log('检测到评教页面,开始自动评教...');
        
        // 自动选择前7个选项的"A 好"
        function selectAllAsGood() {
            let successCount = 0;
            let totalCount = 0;
            
            // 获取表格所有行
            const rows = evaluateContent.querySelectorAll('table.gridtable tr');
            
            // 记录总评教项目数量(减去表头行)
            totalCount = rows.length - 1;
            
            // 处理前7个评教项目或全部项目(如果少于7个)
            const processCount = Math.min(7, totalCount);
            
            // 从第1行(索引为1,跳过表头行)开始处理
            for (let i = 1; i <= processCount; i++) {
                const row = rows[i];
                
                // 查找该行中所有单选按钮
                const radios = row.querySelectorAll('input[type="radio"]');
                
                // 找到标记为"A 好"的单选按钮
                // 通过检查按钮旁边的label文本来识别"A 好"选项
                for (const radio of radios) {
                    const radioId = radio.id;
                    const label = row.querySelector(`label[for="${radioId}"]`);
                    
                    if (label && label.textContent.includes('A 好')) {
                        // 选中"A好"选项
                        radio.checked = true;
                        
                        // 触发change事件
                        const event = new Event('change', { bubbles: true });
                        radio.dispatchEvent(event);
                        
                        console.log(`已将选项 ${i} 设置为"A 好"`);
                        successCount++;
                        break;
                    }
                }
            }
            
            // 显示操作完成提示
            showNotification(`自动评教已完成,成功设置 ${successCount}/${processCount} 个选项为"A 好"`);
            
            return { success: successCount, total: processCount };
        }
        
        // 显示通知
        function showNotification(message) {
            const notification = document.createElement('div');
            notification.textContent = message;
            notification.style.cssText = `
                position: fixed;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                background-color: rgba(0, 128, 0, 0.8);
                color: white;
                padding: 15px 20px;
                border-radius: 5px;
                font-size: 16px;
                z-index: 10000;
                box-shadow: 0 2px 10px rgba(0,0,0,0.3);
                transition: opacity 0.5s;
            `;
            document.body.appendChild(notification);
            
            // 3秒后淡出
            setTimeout(function() {
                notification.style.opacity = '0';
                setTimeout(function() {
                    if (notification.parentNode) {
                        document.body.removeChild(notification);
                    }
                }, 500);
            }, 3000);
        }
        
        // 创建控制面板
        function createControlPanel(result) {
            // 如果已经存在控制面板,更新状态
            const existingPanel = document.getElementById('autoEvaluatePanel');
            if (existingPanel) {
                const statusText = existingPanel.querySelector('.status-text');
                if (statusText && result) {
                    statusText.textContent = `已自动选择前 ${result.success}/${result.total} 个选项为"A 好"`;
                    statusText.style.color = result.success === result.total ? 'green' : 'orange';
                }
                return;
            }
            
            const panel = document.createElement('div');
            panel.id = 'autoEvaluatePanel';
            panel.style.cssText = `
                position: fixed;
                top: 20px;
                right: 20px;
                background-color: #f8f8f8;
                border: 1px solid #ddd;
                border-radius: 8px;
                padding: 15px;
                box-shadow: 0 2px 10px rgba(0,0,0,0.2);
                z-index: 9999;
                font-family: "Microsoft YaHei", Arial, sans-serif;
            `;
            
            const title = document.createElement('div');
            title.textContent = '自动评教控制面板';
            title.style.cssText = `
                font-weight: bold;
                margin-bottom: 12px;
                font-size: 16px;
                color: #333;
                border-bottom: 1px solid #eee;
                padding-bottom: 8px;
            `;
            
            const statusText = document.createElement('div');
            statusText.className = 'status-text';
            statusText.textContent = result ? 
                `已自动选择前 ${result.success}/${result.total} 个选项为"A 好"` : 
                '准备执行自动评教...';
            statusText.style.cssText = `
                color: ${result && result.success === result.total ? 'green' : 'orange'};
                margin-bottom: 10px;
                font-size: 14px;
            `;
            
            const button = document.createElement('button');
            button.textContent = '重新执行自动评教';
            button.style.cssText = `
                padding: 6px 12px;
                cursor: pointer;
                background-color: #4CAF50;
                color: white;
                border: none;
                border-radius: 4px;
                font-size: 14px;
                margin-top: 8px;
            `;
            button.onmouseover = function() { this.style.backgroundColor = '#45a049'; };
            button.onmouseout = function() { this.style.backgroundColor = '#4CAF50'; };
            button.onclick = function() {
                const result = selectAllAsGood();
                createControlPanel(result); // 更新控制面板状态
            };
            
            panel.appendChild(title);
            panel.appendChild(statusText);
            panel.appendChild(button);
            document.body.appendChild(panel);
        }
        
        // 自动执行评教操作
        setTimeout(function() {
            const result = selectAllAsGood();
            createControlPanel(result);
        }, 1000);
    }
    
    // 页面加载完成后执行
    window.addEventListener('load', autoEvaluate);
    
    // 为支持动态加载的页面,定期检查
    let checkCount = 0;
    const maxChecks = 10; // 最多检查10次
    
    const checkInterval = setInterval(function() {
        if (document.getElementById('courseEvaluateContent')) {
            autoEvaluate();
            clearInterval(checkInterval);
        } else {
            checkCount++;
            if (checkCount >= maxChecks) {
                clearInterval(checkInterval);
            }
        }
    }, 1000); // 每秒检查一次
})(); 

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址