// ==UserScript== // @name 物理实验助手 // @namespace http://tampermonkey.net/ // @version 1.1 // @description 专为实验平台设计,自动提取隐藏域答案,美化显示面板,支持一键勾选,提高实验效率。 // @author 毫厘 // @match http://59.69.101.153/lab/Reports/* // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; const options = ['A', 'B', 'C', 'D']; const inputIds = ["result_refer_pre0", "result_refer_pre1", "result_refer_pre2", "result_refer_pre3", "result_refer_pre4"]; // 1. 创建美化的 UI 面板 function createPanel() { const panel = document.createElement('div'); panel.id = 'auto-helper-panel'; panel.innerHTML = `
实验助手 v1.1
正在获取答案...
`; document.body.appendChild(panel); // 添加样式 const style = document.createElement('style'); style.textContent = ` #auto-helper-panel { position: fixed; top: 20px; right: 20px; width: 220px; background: #ffffff; border-radius: 10px; z-index: 10000; box-shadow: 0 4px 15px rgba(0,0,0,0.15); font-family: sans-serif; overflow: hidden; border: 1px solid #eee; transition: all 0.3s ease; } #helper-header { background: #4CAF50; color: white; padding: 10px 15px; display: flex; justify-content: space-between; align-items: center; font-weight: bold; } #toggle-btn { background: rgba(255,255,255,0.2); border: none; color: white; cursor: pointer; border-radius: 3px; } #helper-body { padding: 15px; transition: max-height 0.3s ease; overflow: hidden; } #answer-list { margin-bottom: 15px; font-size: 13px; color: #333; line-height: 1.6; } .answer-item { border-bottom: 1px dashed #eee; padding: 4px 0; } .answer-val { color: #e91e63; font-weight: bold; margin-left: 5px; } #auto-fill-btn { width: 100%; background: #4CAF50; color: white; border: none; padding: 8px; border-radius: 5px; cursor: pointer; font-size: 14px; transition: background 0.2s; } #auto-fill-btn:hover { background: #45a049; } #helper-footer { font-size: 10px; color: #999; margin-top: 10px; text-align: center; } .collapsed #helper-body { max-height: 0; padding: 0; } `; document.head.appendChild(style); // 绑定折叠事件 document.getElementById('toggle-btn').onclick = () => { panel.classList.toggle('collapsed'); document.getElementById('toggle-btn').textContent = panel.classList.contains('collapsed') ? '+' : '-'; }; // 绑定自动填写事件 document.getElementById('auto-fill-btn').onclick = selectAnswers; } // 2. 解析答案并更新面板 function updateAnswers() { let listHtml = ''; inputIds.forEach((id, index) => { let hiddenInput = document.getElementById(id); if (hiddenInput) { let value = hiddenInput.value; let selected = []; for (let i = 0; i < value.length; i++) { if (value[i] === '1') selected.push(options[i]); } listHtml += `
第${index + 1}题:${selected.join('') || '无'}
`; } }); document.getElementById('answer-list').innerHTML = listHtml || '未找到隐藏答案字段'; } // 3. 自动勾选功能 function selectAnswers() { inputIds.forEach((id, index) => { let hiddenInput = document.getElementById(id); if (!hiddenInput) return; let value = hiddenInput.value; for (let i = 0; i < value.length; i++) { let selector = `#pre${index}_op${i}`; let checkbox = document.querySelector(selector); if (checkbox) { checkbox.checked = (value[i] === '1'); } } }); const btn = document.getElementById('auto-fill-btn'); btn.textContent = '勾选完成!'; btn.style.background = '#2196F3'; setTimeout(() => { btn.textContent = '一键自动勾选'; btn.style.background = '#4CAF50'; }, 2000); } // 延迟初始化,确保页面 DOM 加载完毕 window.addEventListener('load', () => { createPanel(); updateAnswers(); }); })();