// ==UserScript== // @name 天津医科大学临床医学院教学管理系统自动评教(最终版) // @namespace http://tampermonkey.net/ // @version 3.6 // @description 100%可用的自动填写评分、优点建议并提交 // @author ZJX // @match http://180.213.3.14:18880/eams/* // @match http://*/eams/quality/stdEvaluate.action* // @grant none // @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js // ==/UserScript== (function() { 'use strict'; // 配置项 const config = { defaultScore: '0', // 评分选项(0:优秀) // 优点和建议内容 advantagesText: '教师授课条理清晰,重点突出。', suggestionsText: '建议增加一些问答环节。', delays: { init: 1500, // 初始延迟 between: 300, // 操作间延迟 submit: 3000 // 填写完成后提交延迟 }, retryTimes: 5, // 重试次数 highlight: true, // 调试高亮 autoSubmit: true // 是否自动提交 }; // 主执行函数 function initAutoEvaluate() { console.log('自动评教脚本启动...'); setTimeout(startProcessing, config.delays.init); } function startProcessing() { console.log('开始处理评教表单...'); processEvaluation(() => { processAdviceSection(() => { if (config.autoSubmit) { setTimeout(autoSubmitForm, config.delays.submit); } }); }); } // 处理评分部分 function processEvaluation(callback, retry = 0) { try { console.log('正在处理评分部分...'); const excellentOptions = $('input.option-radio[value="'+config.defaultScore+'"]').toArray(); if (excellentOptions.length === 0 && retry < config.retryTimes) { console.log(`未找到评分选项,第${retry + 1}次重试...`); setTimeout(() => processEvaluation(callback, retry + 1), config.delays.between); return; } excellentOptions.forEach((radio, index) => { setTimeout(() => { radio.checked = true; $(radio).trigger('change'); if (config.highlight) { $(radio).closest('li').css('background-color', '#e6f7e6'); } console.log(`已选择第${index + 1}个评分项: ${radio.value}`); if (index === excellentOptions.length - 1) { setTimeout(callback, config.delays.between); } }, index * config.delays.between); }); if (excellentOptions.length === 0) { console.warn('未找到任何评分选项'); setTimeout(callback, config.delays.between); } } catch (error) { console.error('评分处理出错:', error); setTimeout(callback, config.delays.between); } } // 处理优点及建议部分 function processAdviceSection(callback, retry = 0) { try { console.log('正在处理优点建议部分...'); // 使用jQuery选择器 const advantageTextarea = $('font.indexno:contains("5.1")').closest('.qBox').find('textarea')[0]; const suggestionTextarea = $('font.indexno:contains("5.2")').closest('.qBox').find('textarea')[0]; if (advantageTextarea && suggestionTextarea) { console.log('找到优点和建议文本框'); fillTextarea(advantageTextarea, config.advantagesText, '优点'); setTimeout(() => { fillTextarea(suggestionTextarea, config.suggestionsText, '建议'); setTimeout(callback, config.delays.between); }, config.delays.between); } else if (retry < config.retryTimes) { console.log(`未找到建议输入框,第${retry + 1}次重试...`); setTimeout(() => processAdviceSection(callback, retry + 1), config.delays.between); } else { console.error('最终未能找到建议输入框'); setTimeout(callback, config.delays.between); } } catch (error) { console.error('填写建议部分出错:', error); setTimeout(callback, config.delays.between); } } // 自动提交表单 function autoSubmitForm() { try { console.log('准备提交表单...'); const submitBtn = $('#sub')[0] || $('input[type="button"][value="提交"]')[0]; if (submitBtn) { console.log('找到提交按钮'); if (config.highlight) { $(submitBtn).css({ 'border': '2px solid #ff0000', 'background-color': '#ffe6e6' }); } // 使用jQuery触发点击事件 $(submitBtn).trigger('click'); // 处理可能的确认对话框 setTimeout(() => { const confirmBtn = $('.ui-dialog-buttonpane button:first-child')[0]; if (confirmBtn) { console.log('发现确认对话框,点击确认'); $(confirmBtn).trigger('click'); } }, 1000); } else { console.warn('未找到提交按钮,请手动提交'); } } catch (error) { console.error('自动提交出错:', error); } } // 辅助函数:填写文本框 function fillTextarea(textarea, text, fieldName) { if (!textarea) { console.warn(`${fieldName}文本框未找到`); return; } $(textarea).val(text).trigger('input'); if (config.highlight) { $(textarea).css({ 'border': '2px solid #ffa500', 'background-color': '#fff8e6' }); } console.log(`已填写${fieldName}内容,字数: ${text.length}`); console.log(`关联元素:`, textarea); } // 启动脚本 $(document).ready(function() { initAutoEvaluate(); }); })();