// ==UserScript== // @name 北理工教评 // @namespace http://tampermonkey.net/ // @version 0.3 // @description 自定义一键评价 // @match https://pj.bit.edu.cn/pjxt2.0/stpj/* // @grant GM_setValue // @grant GM_getValue // @downloadURL none // ==/UserScript== (function () { 'use strict'; // 创建配置面板 function createConfigPanel() { // 创建配置面板容器 const panel = document.createElement('div'); // 获取保存的位置,如果没有则使用默认位置 const savedPosition = GM_getValue('panelPosition', { top: '50px', left: 'auto', right: '10px' }); panel.style.position = 'fixed'; panel.style.top = savedPosition.top; panel.style.left = savedPosition.left; panel.style.right = savedPosition.right; panel.style.width = '250px'; panel.style.backgroundColor = '#f0f0f0'; panel.style.border = '1px solid #ccc'; panel.style.padding = '15px'; panel.style.zIndex = '10000'; panel.style.borderRadius = '5px'; panel.style.boxShadow = '0 0 10px rgba(0,0,0,0.1)'; // 标题 const title = document.createElement('h3'); title.textContent = '教师评价配置'; title.style.textAlign = 'center'; title.style.marginBottom = '15px'; panel.appendChild(title); // 选项单选组 const options = [ { text: '神中神', value: 1 }, { text: '挺好', value: 2 }, { text: '一般', value: 3 }, { text: '半唐', value: 4 }, { text: '全唐', value: 5 } ]; // 创建单选按钮 const radioContainer = document.createElement('div'); radioContainer.style.marginBottom = '15px'; options.forEach((option, index) => { const radioDiv = document.createElement('div'); radioDiv.style.marginBottom = '5px'; const radio = document.createElement('input'); radio.type = 'radio'; radio.name = 'evaluationOption'; radio.id = `option${index}`; radio.value = option.value; // 读取之前保存的选项 const savedOption = GM_getValue('selectedOption', 1); radio.checked = parseInt(savedOption) === option.value; const label = document.createElement('label'); label.htmlFor = `option${index}`; label.textContent = option.text; label.style.marginLeft = '5px'; // 设置选中项的样式 if (radio.checked) { label.style.fontWeight = 'bold'; label.style.color = '#4CAF50'; } // 添加点击事件 radio.addEventListener('change', () => { // 更新所有label的样式 radioContainer.querySelectorAll('label').forEach(l => { l.style.fontWeight = 'normal'; l.style.color = 'black'; }); // 设置当前选中项的样式 label.style.fontWeight = 'bold'; label.style.color = '#4CAF50'; // 自动保存选项 GM_setValue('selectedOption', option.value); }); radioDiv.appendChild(radio); radioDiv.appendChild(label); radioContainer.appendChild(radioDiv); }); panel.appendChild(radioContainer); // 意见输入框 const commentLabel = document.createElement('label'); commentLabel.textContent = '意见内容:'; const commentInput = document.createElement('input'); commentInput.type = 'text'; commentInput.id = 'commentInput'; commentInput.style.width = '100%'; commentInput.style.marginBottom = '10px'; commentInput.value = GM_getValue('defaultComment', '好'); // 自动保存意见内容 commentInput.addEventListener('input', () => { GM_setValue('defaultComment', commentInput.value); }); panel.appendChild(commentLabel); panel.appendChild(commentInput); // 创建按钮容器 const buttonContainer = document.createElement('div'); buttonContainer.style.display = 'flex'; buttonContainer.style.gap = '10px'; buttonContainer.style.marginTop = '10px'; // 一键评价按钮 const evaluateButton = document.createElement('button'); evaluateButton.textContent = '一键评价'; evaluateButton.style.width = '50%'; evaluateButton.style.backgroundColor = '#4CAF50'; evaluateButton.style.color = 'white'; evaluateButton.style.padding = '8px'; evaluateButton.style.border = 'none'; evaluateButton.style.borderRadius = '3px'; evaluateButton.style.cursor = 'pointer'; evaluateButton.addEventListener('click', autoEvaluate); // 提交按钮 const submitButton = document.createElement('button'); submitButton.textContent = '提交评价'; submitButton.style.width = '50%'; submitButton.style.backgroundColor = '#ffa500'; submitButton.style.color = 'white'; submitButton.style.padding = '8px'; submitButton.style.border = 'none'; submitButton.style.borderRadius = '3px'; submitButton.style.cursor = 'pointer'; submitButton.addEventListener('click', () => { if (typeof savePjxx === 'function') { savePjxx('1'); } else { alert('未找到提交函数,请手动点击页面的提交按钮'); } }); // 在buttonContainer中添加第三个按钮 const filterButton = document.createElement('button'); filterButton.textContent = '筛选未评'; filterButton.style.width = '100%'; // 让这个按钮占据整行 filterButton.style.backgroundColor = '#2196F3'; // 使用蓝色区分 filterButton.style.color = 'white'; filterButton.style.padding = '8px'; filterButton.style.border = 'none'; filterButton.style.borderRadius = '3px'; filterButton.style.cursor = 'pointer'; filterButton.style.marginTop = '10px'; // 与上面的按钮组保持间距 filterButton.addEventListener('click', () => { // 获取select元素 const select = document.querySelector('#ztTab'); if (select) { // 设置值为"3"(未评) select.value = "3"; // 触发change事件 select.dispatchEvent(new Event('change')); // 处理chosen插件 if (window.jQuery) { try { // 更新chosen插件的显示 jQuery('#ztTab').trigger('chosen:updated'); // 触发chosen的change事件 jQuery('#ztTab').trigger('change'); } catch (e) { console.log('Chosen plugin update failed:', e); } } queryLike(); } else { alert('未找到状态选择框'); } }); // 将按钮添加到容器中 buttonContainer.appendChild(evaluateButton); buttonContainer.appendChild(submitButton); panel.appendChild(filterButton); // 将按钮容器添加到面板中 panel.appendChild(buttonContainer); // 添加拖动功能 panel.style.cursor = 'move'; let isDragging = false; let currentX; let currentY; let initialX; let initialY; panel.addEventListener('mousedown', e => { if (e.target === panel || e.target === title) { isDragging = true; initialX = e.clientX - panel.offsetLeft; initialY = e.clientY - panel.offsetTop; } }); document.addEventListener('mousemove', e => { if (isDragging) { e.preventDefault(); currentX = e.clientX - initialX; currentY = e.clientY - initialY; panel.style.left = currentX + 'px'; panel.style.top = currentY + 'px'; panel.style.right = 'auto'; } }); document.addEventListener('mouseup', () => { if (isDragging) { // 保存当前位置 GM_setValue('panelPosition', { top: panel.style.top, left: panel.style.left, right: 'auto' }); } isDragging = false; }); document.body.appendChild(panel); } // 自动评价函数 function autoEvaluate() { const selectedOption = GM_getValue('selectedOption', 1); const comment = GM_getValue('defaultComment', '好'); // 选择所有对应序号的单选按钮并点击 document.querySelectorAll(`.wjgl_input[id$="_${selectedOption}"]`).forEach(radio => { if (!radio.checked) { radio.click(); } }); // 填写所有文本框 document.querySelectorAll('textarea').forEach(textarea => { textarea.value = comment; const event = new Event('change', { bubbles: true }); textarea.dispatchEvent(event); }); } // 页面加载完成后添加配置面板 function init() { window.addEventListener('load', () => { setTimeout(createConfigPanel, 0); }); } // 启动脚本 init(); })();