1.购买服务器阿里云:服务器购买地址https://t.aliyun.com/U/PfsP97若失效,可用地址
阿里云:
服务器购买地址
https://t.aliyun.com/U/PfsP97若失效,可用地址
https://www.aliyun.com/activity/wuying/dj?source=5176.29345612&userCode=49hts92d腾讯云:
https://curl.qcloud.com/wJpWmSfU若失效,可用地址
https://cloud.tencent.com/act/cps/redirect?redirect=2446&cps_key=ad201ee2ef3b771157f72ee5464b1fea&from=console华为云
https://activity.huaweicloud.com/cps.html?fromacct=64b5cf7cc11b4840bb4ed2ea0b2f4468&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=2019052.部署教程
3.代码如下
(function ($) {'use strict';let A = 0, B = 1, C = 2, D = 3, E = 4, F = 5, G = 6;let shuffle = function (array) {for (var j, x, i = array.length; i; j = parseInt(Math.random() * i), x = array[--i], array[i] = array[j], array[j] = x) ;return array;};let url = {jq: /https:\/\/www\.wjx\.cn\/jq\/\w+\.aspx/.test(location.href),hj: /https:\/\/www\.wjx\.cn\/hj\/\w+\.aspx/.test(location.href),m: /https:\/\/www\.wjx\.cn\/m\/\w+\.aspx/.test(location.href)};(function (setValue) {})(GM.setValue);var $fieldset = $('#fieldset1');$.extend({// 1. 选择题(单选+多选)selectQuestion: function (option) {var options = $.extend({$fieldset: undefined, // 表单questionSelector: '', // 每个问题的selectortitleSelector: '', // 每个问题的标题selectoranswerSelector: '', // 每个问题的答案selectorisRadio: function ($answers) {return true;},isCheckbox: function ($answers) {return true;}}, option);options.$fieldset.find(options.questionSelector).each(function () {var $this = $(this);var $answers = $this.find(options.answerSelector);let fillInput = function (value) {// 1. 单选题自动填写if (options.isRadio($answers)) {// 默认随机填写if(!value) { value = Math.round(Math.random() * ($answers.length - 1)); }$answers.eq(value).click();}// 2. 多选题自动填写, 打乱按钮顺序, 默认随机点击多个答案if (options.isCheckbox($answers)) {// 默认随机点击多个答案if(!value || !value.length) {value = [];$answers = shuffle($answers); // 打乱顺序let num = Math.round(Math.random() * ($answers.length - 1)) || 1;for (let i = 0, len = num; i < len; i++) {value.push(i);}}$.each(value, (index, item) => $answers.eq(item).click());}};// 1. 初始化 是否记住选项的checkboxlet $title = $this.find(options.titleSelector), title = $title.text();let $remember = $('<input type="checkbox" name="' + title + 'Remember">');$remember.on('change', function () {let checked = $(this).is(':checked');GM.setValue(title+'Remember', pattern);});$title.append($remember).append('(记住选项)');// 2. 恢复上次选中的选项GM.getValue(title+'Remember').then(function (value) {$remember.prop('checked', !!value);fillInput(value);});});},// 2. 比重题ratingQuestion: function (option) {return;var options = $.extend({$fieldset: undefined, // 表单answerSelector: '' // 答案的selector}, option);options.$fieldset.find(options.answerSelector).each(function () {var $this = $(this);var $td = $this.children('td');// 随机点击某一个选项$td.eq(Math.round(Math.random() * ($td.length - 1))).click();});},// 3. 自动提交autoSubmit: function (option) {var options = $.extend({enabled: false, // 默认关闭自动提交autoReopen: false, // 提交后是否重新打开问卷, 用于刷问卷$button: undefined // 提交按钮}, option);// 1. 点击获取验证码$('#yucinput').click().focus();// 2. 自动提交, 或者滚动到页面底部if (options.enabled) {options.$button.click();} else {$("html, body").animate({scrollTop: $(document).height()}, 1000);}// 3. 提交时在新标签页打开问卷if (options.autoReopen) {var reopen = function () {window.open(location.href, '_blank');setTimeout(function () {window.close();}, 1000);};$('#yucinput').keypress(function (e) {if (e.which == 13) {reopen();}});options.$button.on('click', reopen);}}});(function () {let valid = url.jq || url.hj;if (!valid) {return;}console.log('匹配jq模式问卷');$.selectQuestion({$fieldset: $fieldset,questionSelector: '.div_question',titleSelector: '.div_title_question',answerSelector: '.div_table_radio_question .ulradiocheck li',isRadio: function ($answers) {return $answers.find('a:first').hasClass('jqRadio');},isCheckbox: function ($answers) {return $answers.find('a:first').hasClass('jqCheckbox');}});$.ratingQuestion({$fieldset: $fieldset,answerSelector: 'div.div_table_radio_question tbody tr'});$.autoSubmit({enabled: false,autoReopen: false,$button: $('input.submitbutton')});})();(function () {let valid = url.m;if (!valid) {return;}console.log('匹配m模式问卷');$.selectQuestion({$fieldset: $fieldset,questionSelector: '.field',titleSelector: '.field-label',answerSelector: '.ui-controlgroup div',isRadio: function ($answers) {return $answers.hasClass('ui-radio');},isCheckbox: function ($answers) {return $answers.hasClass('ui-checkbox');}});$.ratingQuestion({$fieldset: $fieldset,answerSelector: '.matrix-rating tbody tr[tp]'});$.autoSubmit({enabled: false,autoReopen: false,$button: $('#divSubmit').find('a.button')});})();})(jQuery);
解析
该脚本为问卷星自动随机填写脚本,主要作用包括:
在问卷星页面(PC 的 jq/hj 模式与移动端 m 模式)自动随机作答:
支持单选题、多选题、比重/打分题(rating);
可选 自动提交 与 提交后自动重新打开(用于刷卷)。
允许为每道题开启"记住上次选项"(基于
GM.setValue / GM.getValue)以复用之前的回答。
结构与关键点
URL 适配:用正则判断当前是
jq、hj还是m模式,从而选择不同的 DOM 选择器与逻辑。随机打乱工具:
shuffle(array)用于多选题时随机化选项点击顺序。入口:根据模式分别执行一组初始化(PC 一组、移动端一组)。
核心方法与职责
1) $.selectQuestion(options)
用于单选/多选题的随机选择与(可选)记忆:
传入题块、题目标题、选项的选择器,以及如何判定是单选/多选的回调:
isRadio($answers):判断该题是否单选;isCheckbox($answers):判断该题是否多选。逻辑:
单选题:随机选中一个选项(或使用"记住"的值)。
多选题:先打乱选项顺序,随机决定勾选数量与具体项(或使用"记住"的值)。
题目标题处会追加一个"(记住选项)"复选框;若勾选,则把本题的选择写入
GM.setValue,下次进入页面时通过GM.getValue恢复并自动勾选。
小提示:源码里
$remember.on('change')里GM.setValue(title+'Remember', pattern)的pattern变量未定义,实际应保存当前选择的值(如单选的索引或多选的索引数组)。这是一个小 bug,需自行修正。
2) $.ratingQuestion(options)
用于比重/打分题(矩阵评分等):
根据传入的评分行选择器,随机点击一列作为该行评分。
当前文件里在函数开头
return;直接返回,相当于暂时禁用。想启用可移除该行。
3) $.autoSubmit(options)
控制验证码聚焦/自动提交/自动重开:
enabled:是否自动点"提交";autoReopen:提交后是否新开标签再重新加载问卷(用于循环刷答卷);会自动点击验证码输入框
#yucinput并聚焦;若未开启自动提交则滚动到页底。
两套初始化(根据页面形态)
PC(jq/hj)
传入:questionSelector: '.div_question'titleSelector: '.div_title_question'answerSelector: '.div_table_radio_question .ulradiocheck li'isRadio:检查子元素是否带jqRadioisCheckbox:检查子元素是否带jqCheckboxrating 用
div.div_table_radio_question tbody tr提交按钮
input.submitbutton移动端(m)
传入:questionSelector: '.field'titleSelector: '.field-label'answerSelector: '.ui-controlgroup div'isRadio:是否有ui-radioisCheckbox:是否有ui-checkboxrating 用
.matrix-rating tbody tr[tp]提交按钮
#divSubmit a.button
注意:
本文部分变量已做脱敏处理,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。技术层面需要提供帮助,可以通过打赏的方式进行探讨。
历史脚本txt文件获取>>
没有评论:
发表评论