// ==UserScript== // @name 自动勾选实验选项 // @namespace http://tampermonkey.net/ // @version 1.3 // @description 根据隐藏域自动勾选答案并提交表单 // @author You // @match http://59.69.103.147/Reports/* // @match http://59.69.101.153/lab/Reports/* // @grant none // ==/UserScript== (function() { 'use strict'; // 代码逻辑 // 定义选项数组 const options = ['A', 'B', 'C', 'D']; // 用于映射每个隐藏域的ID const inputIds = [ "result_refer_pre0", "result_refer_pre1", "result_refer_pre2", "result_refer_pre3", "result_refer_pre4" ]; // 首先清除所有选项的选中状态 inputIds.forEach((id, index) => { for (let i = 0; i < options.length; i++) { let selector = `#pre${index}_op${i}`; let optionElement = document.querySelector(selector); // 如果选项存在,则取消选中 if (optionElement) { optionElement.checked = false; } } }); // 遍历每个输入项,根据隐藏域的值选择对应的选项 inputIds.forEach((id, index) => { let value = document.getElementById(id).value; // 获取value值 // 根据value的每一位判断选择的选项 for (let i = 0; i < value.length; i++) { if (value[i] === '1') { // 构造选择器,勾选相应的选项 let selector = `#pre${index}_op${i}`; let optionElement = document.querySelector(selector); // 如果找到了对应的选项,设置其为选中状态 if (optionElement) { optionElement.checked = true; } } } }); })();