问卷填报名表油猴脚本
仅针对特定问卷// UserScript // name 问卷自动填写 // match https://v.wjx.cn/vm/tTolo5.aspx* // grant none // run-at document-idle // /UserScript (function () { use strict; // 按顺序填你的答案,几个填空写几个 const ANSWERS [ 张三, 12345, spacex, 111111 ]; const sleep ms new Promise(r setTimeout(r, ms)); const rand (a, b) a Math.random() * (b - a); function getBoxes() { return document.querySelectorAll( #divQuestion input[typetext], #divQuestion textarea ); } function getSubmit() { return document.querySelector(#ctlNext); } async function run() { // 轮询等表单可填 let boxes, submit; for (let i 0; i 2; i) { // 最多等约 2 钟 boxes getBoxes(); submit getSubmit(); if (boxes.length 0 submit) break; await sleep(500); } if (!boxes || boxes.length 0 || !submit) return; // 按顺序填,每题之间停顿,避免秒交 for (let i 0; i ANSWERS.length i boxes.length; i) { const el boxes[i]; el.focus(); el.value ANSWERS[i]; // 触发问卷星监听的事件,否则它可能认为没填 el.dispatchEvent(new Event(input, { bubbles: true })); el.dispatchEvent(new Event(change, { bubbles: true })); el.dispatchEvent(new Event(blur, { bubbles: true })); await sleep(rand(400, 900)); } await sleep(rand(500, 1000)); submit.click(); console.log(已点提交); } run(); })();