参考链接地址:https://www.cnblogs.com/FHC1994/p/11721723.html
(过程需要翻墙,问卷星链接需要在浏览器打开,在微信直接打开的链接本脚本无法使用)
①安装脚本:
油侯脚本是一款免费的浏览器扩展和最为流行的用户脚本管理器,增强了用户对浏览体验的控制权。油侯脚本下载地址:http://www.tampermonkey.net/
②点击图片中红框位置按钮(因为我已经下载了,所以显示的是已安装)
③拉到页面最下方,点击添加至Chrome按钮
④添加完成后,在Chrome浏览器的右上方有下图所示按钮,点击之后,选择添加新脚本
⑤复制如下代码至“添加新脚本”页面内
// ==UserScript==
// @name 问卷星测试——支持input radio checkbox
// @version 1.1
// @description 测试
// @author 蛋片鸡
// @match https://www.wjx.top/*
// @match https://www.wjx.cn/*
// @grant none
// @require https://code.jquery.com/jquery-3.4.1.min.js
// ==/UserScript==
/*
**info 第一个参数:对应的填入选项(字符串)
**info 第二个参数:匹配的标题(正则表达式)
**info 第三个参数:(可选),当答题框为单选|多选时匹配的选项(正则表达式)
*/
(function() {
'use strict';
const info=[
["蛋片鸡",/(姓名)|(名字)/],
["单选框_年级",/(年级)/,/(18级)/],
["18711111",/(学号)/],
["11011001100",/(联系方式)|(电话)|(手机)|(手机号)/],
["多选框_你好呀",/(你好呀)/,/(开始)|(中间)|(结束)/]
];
const ini={
module:".field.ui-field-contain",//每个问题模块
title:".field-label",//标题
type:{ //key对应别名,value对应html的节点
"input_text":".ui-input-text",
"radio":".ui-radio",
"checkbox":".ui-checkbox"
}
};
$(document).ready(function(){
let itemNum = 0;
$(ini.module).each(function(){
itemNum += 1;
let title=$(this).find(ini.title).text();
console.log("each循环" + itemNum);
//判断类别
let count = 0 ;
for(let i=0;i<info.length;i++){//匹配用户信息
if(info[i][1].test(title)){//匹配到一处信息,判断答题框类型,加break!
for(let tp in ini.type){
let dom=$(this).find(ini.type[tp]);
if(dom.length>0){
switch(tp){
case "input_text":
$("#q"+itemNum)[0].value = info[i][0]; //赋值
break;
case "radio":
$(this).find(".ui-radio").each(function(){
if(info[i].length>=3&&info[i][2].test($(this).text())){
var id=$(this).find('input').attr('id');
$("#"+id).prop("checked",true);
}
});
break;
case "checkbox":
$(this).find(".ui-checkbox").each(function(){
console.log("outsidebox" + count);
if(info[i].length>=3&&info[i][2].test($(this).text())){
var id=$(this).find('input').attr('id');
$("#"+id).prop("checked",true);
}
});
break;
default:console.log("ini.type中没有匹配"+tp+"的键值");
}
break;
}
}
break;
}
}
});
//$("#ctlNext")[0].click();
});
})();
⑥在“添加至新脚本”页面中,点击左上角的保存按钮
⑦打开问卷星地址,已经实现根据设定的答案,自动填写。
⑧额外说明:
a、因为本人对js不太熟悉,所以有个问题要说明。当我们刷新页面的时候,发现填空题填写了,但是单选和多选是没有选上的,其实在js脚本里面,代码里是已经选上对应的选项了的,只不过不知道样式怎么不显示。(可以通过创建和我一样问题的问卷,然后做一下这份问卷,再提交问卷,最后到问卷后台查看提交的记录中是否有单选和多选记录即可)
b、因为本js脚本是根据问卷星页面源代码进行编写的,有时候问卷星修改了html节点的命名,就需要去修改本例对应的节点名称,这边附上本例测试时间,问卷星的源代码和问卷星的链接地址(https://www.wjx.cn/m/49588636.aspx),供大家参考对照,修改节点名称。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>测试使用</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1,user-scalable=no" />
<meta name="format-detection" content="telephone=no" />
<link rel="canonical" href="https://www.wjx.cn/jq/49588636.aspx" />
<meta property="og:type" content="article" />
<meta property="og:release_date" content="2019-11-12" />
<meta property="og:image" content="https://image.wjx.com/images/wlogo.png" />
<meta property="og:title" content="测试使用" />
<meta property="og:description" content="我在问卷星上发布了问卷《测试使用》,请帮忙填写,非常感谢!" />
<meta name="applicable-device" content="mobile" />
<link rel="dns-prefetch" href="//sojump.cn-hangzhou.log.aliyuncs.com" />
<script type="text/javascript">
var maxCheatTimes = 0;
var activityId =49588636;
if (window.location.hash) {
window.location.hash = "";
window.location.href = window.location.href.replace("#", "");
}
var isWeiXin=0;
</script>
<link rel="stylesheet" href="/joinnew/css/jqmobo.css?v=973" />
<script src="https://staticfile.qnssl.com/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
!window.jQuery && document.write('<script src="/js/jquery-1.10.2.min.js"><\/script>');
</script>
<script src="/joinnew/js/hintinfo.js?v=2" type="text/javascript"></script>
<script src="/joinnew/js/jqmobo2.js?v=973" type="text/javascript"></script>
<style>
</style>
</head>
<body>
<div id="divTip" style="position:absolute; left: 0; right: 0; z-index: 10; display: none; font-size: 14px; color: #ffffff; line-height: 24px; padding: 8px; background-color: #f95b5b;"></div>
<div id="tipHeight" style="height:40px;display:none;"></div>
<div style="background: #fff; position: fixed; top: 0px; left: 0px; right: 0px; bottom: 0px; z-index: 2; display: none;" id="divWorkError">
</div>
<form id="form1" method="post" action="https://www.wjx.cn/joinnew/processjq.ashx?curid=49588636" style="overflow:hidden;">
<div id="divLoadAnswer" style="display: none; font-size: 14px;line-height:24px;padding:6px 8px;background-color: #fff9f0;">
</div>
<div id="toptitle">
<h1 class="htitle" id="htitle"> 测试使用</h1>
</div>
<div id="divBackgroundWrap"></div>
<div id="divMaxTime" style="display: none; background: #FFEAEA; color: #FF5760; font-size: 16px; height: 40px; left: 0; line-height: 40px; position: fixed; text-align: center; top: 0; width: 100%; z-index: 100;">
<span id="spanTimeTip"></span>
<span id="spanMaxTime"></span>
</div>
<div id="divContent" class="divContent">
<div class="checkInMode__head clearfix" id="divCheckInMode" style="display: none;">
<div class="wjxCountDown__wrap game_time">
<div class="countDown__hold">
<div class="round round1"></div>
</div>
<div class="countDown__hold">
<div class="round round2"></div>
</div>
<div class="countDown__bg"></div>
<div class="CountDown__frame"></div>
<div class="countDown__time">
<div class="countDown__time--num" id="divCGMaxTime">
10
</div>
<div class="countDown__time--unit">
秒
</div>
</div>
</div>
<div class="icon decoration-icon pull-left"></div>
<div class="schedule-wrap pull-right">
<div id="schedule">
1
</div> /
<span id="cgtotal">5</span>题
</div>
</div>
<div id="divDesc" class="formfield">
<span class="description"> 哈哈哈</span>
</div>
<div id="divQuestion">
<fieldset class="fieldset" style="" id="fieldset1">
<div class="field ui-field-contain" id="div1" topic="1" data-role="fieldcontain" type="1">
<div class="field-label">
1. 姓名
</div>
<div class="ui-input-text" style="position:relative;">
<input type="text" id="q1" value="" name="q1" />
</div>
<div class="errorMessage"></div>
</div>
<div class="field ui-field-contain" id="div2" req="1" topic="2" data-role="fieldcontain" type="3">
<div class="field-label">
2. 年级
<span class="req">*</span>
</div>
<div class="ui-controlgroup">
<div class="ui-radio">
<span class="jqradiowrapper"><input type="radio" value="1" id="q2_1" name="q2" style="display:none;" /><a class="jqradio" href="javascript:;"></a></span>
<div class="label" for="q2_1">
16级
</div>
</div>
<div class="ui-radio">
<span class="jqradiowrapper"><input type="radio" value="2" id="q2_2" name="q2" style="display:none;" /><a class="jqradio" href="javascript:;"></a></span>
<div class="label" for="q2_2">
17级
</div>
</div>
<div class="ui-radio">
<span class="jqradiowrapper"><input type="radio" value="3" id="q2_3" name="q2" style="display:none;" /><a class="jqradio" href="javascript:;"></a></span>
<div class="label" for="q2_3">
18级
</div>
</div>
<div class="ui-radio">
<span class="jqradiowrapper"><input type="radio" value="4" id="q2_4" name="q2" style="display:none;" /><a class="jqradio" href="javascript:;"></a></span>
<div class="label" for="q2_4">
19级
</div>
</div>
</div>
<div class="errorMessage"></div>
</div>
<div class="field ui-field-contain" id="div3" topic="3" data-role="fieldcontain" type="1">
<div class="field-label">
3. 学号
</div>
<div class="ui-input-text" style="position:relative;">
<input type="text" id="q3" value="" name="q3" />
</div>
<div class="errorMessage"></div>
</div>
<div class="field ui-field-contain" id="div4" topic="4" data-role="fieldcontain" type="1">
<div class="field-label">
4. 联系方式
</div>
<div class="ui-input-text" style="position:relative;">
<input type="text" id="q4" value="" name="q4" />
</div>
<div class="errorMessage"></div>
</div>
<div class="field ui-field-contain" id="div5" req="1" topic="5" data-role="fieldcontain" type="4">
<div class="field-label">
5. 你好呀
<span class="req">*</span>
<span class="qtypetip"> 【多选题】</span>
</div>
<div class="ui-controlgroup">
<div class="ui-checkbox">
<span class="jqcheckwrapper"><input type="checkbox" value="1" id="q5_1" name="q5" style="display:none;" /><a class="jqcheck" href="javascript:;"></a></span>
<div class="label" for="q5_1">
开始
</div>
</div>
<div class="ui-checkbox">
<span class="jqcheckwrapper"><input type="checkbox" value="2" id="q5_2" name="q5" style="display:none;" /><a class="jqcheck" href="javascript:;"></a></span>
<div class="label" for="q5_2">
中间
</div>
</div>
<div class="ui-checkbox">
<span class="jqcheckwrapper"><input type="checkbox" value="3" id="q5_3" name="q5" style="display:none;" /><a class="jqcheck" href="javascript:;"></a></span>
<div class="label" for="q5_3">
加速
</div>
</div>
<div class="ui-checkbox">
<span class="jqcheckwrapper"><input type="checkbox" value="4" id="q5_4" name="q5" style="display:none;" /><a class="jqcheck" href="javascript:;"></a></span>
<div class="label" for="q5_4">
结束
</div>
</div>
</div>
<div class="errorMessage"></div>
</div>
</fieldset>
</div>
<div id="divMatrixRel" style="position: absolute; display: none; width: 80%; margin: 0 10%;" class="ui-input-text">
<input type="text" placeholder="请注明..." id="matrixinput" style="min-height: 2em; width: 100%; padding: 0.3em 0.6em;" />
</div>
<div id="divMatrixHeader" class="divMatrixHeader" style="position: absolute; display: none; font-size: 12px; color: #333">
</div>
<div class="shopcart" id="shopcart" style="display: none;">
</div>
<div class="footer">
<div class="ValError" id="ValError">
</div>
<div id="captchaOut">
<div id="captchaWrap">
<span id="captchaTit" style="display:none;color:#42B917;"></span>
<div id="captcha" style="margin: 0 auto;"></div>
</div>
</div>
<div id="divSubmit" style="padding: 0px 20px 10px; display: none;">
<div id="tdCode" style="display: none; padding-bottom: 15px;">
<table>
<tbody>
<tr>
<td class="ui-input-text nofocus"> <input id="yucinput" size="14" maxlength="10" type="text" name="yucinput" /> </td>
<td>
<div id="divCaptcha" style="display: none;">
<img alt="验证码" title="看不清吗?点击可以刷新" captchaid="" instanceid="" />
</div> </td>
<td> <img id="imgCode" alt="验证码" title="看不清吗?点击可以刷新" style="vertical-align: bottom; cursor: pointer; display: none;" /> </td>
</tr>
</tbody>
</table>
</div>
<div class="voteDiv">
<a id="ctlNext" href="javascript:;" class="button blue"> 提交</a>
<a href="javascript:;" class="button white ctBack" style="display:none" onclick="location.href=getTpMainUrl()"> 返回</a>
</div>
<div style="margin: 0px 0 10px; padding-top: 10px;">
<a href="/urlreport.aspx?url=49588636" style="float: right; color: #666; font-size: 14px;" class="reportto" rel="nofollow"> 举报</a>
<div style="clear: both;">
</div>
</div>
</div>
<a href="javascript:;" id="cgstartbutton" style="display: none;"></a>
<div id="divSearch" style="background: #020d15; color: #7c7c7c; font-size: 18px; height: 50px; left: 0; line-height: 50px; position: fixed; text-align: center; bottom: 0; width: 100%; z-index: 100; display: none;">
</div>
</div>
</div>
<div id="divPowerBy" style="margin: 0 auto;" class="logofooter">
<div class="wjfooter">
<span id="spanPower"><a href="https://www.wjx.cn/mobile/index.aspx" target="_blank" title="问卷星_不止问卷调查/在线考试">问卷星</a> 提供技术支持</span>
</div>
</div>
<div class="result" id="outdiv">
<div class="indiv" id="indiv">
<i class="icon_close"></i>
<div id="preView_wrap">
<img class="imgresult" id="bigimg" src="" alt="" />
</div>
</div>
</div>
<div id="divTimeUp" style="display: none;">
<div style="padding: 10px; overflow: auto; line-height: 20px; font-size: 16px; text-align: center;" id="divTimeUpTip"></div>
</div>
<input type="hidden" value="2019/11/13 9:36:22" id="starttime" name="starttime" />
<input type="hidden" value="directphone" id="source" name="source" />
</form>
<a id="lnkCity" style="display: none;"></a>
<script type="text/javascript">
var isYdb=0;
var isPub=0;
var isQywx=0;
var cqType=1;
var isDingDing=0;
var ddcorpid="";
var sojumpParm='';
var parmsign='';
var isKaoShi=0;
var lastTopic=0;
var Password = "";
var PasswordExt = "";
var pwdExt="";
var emailName="";
var phoneName="";
var guid = "";
var udsid=0;var fromsour="";
var langVer=0;
var cProvince="";
var cCity="";
var cIp="";
var divTip=document.getElementById("divTip");
var displayPrevPage="none";
var inviteid='';var jbkid='';
var access_token="";
var openid = "";
var wxUserId = "";
var ddUserId = "";
var isQQLogin=0;
var wxthird=0;
var parterts="";
var parterjoiner="";
var partersign="";
var parterrealname="";
var parterextf="";
var parterdept="";
var parterpuser="";
var relusername="";
var relts="";
var relsign="";
var relrealname="";
var reldept="";
var relext="";
var nbk=0;
var corpId="";
var flist=0;
var isPvw=0;
var user_token="";
var IsSampleService=0;
var hashb=0;
var sjUser='';
var sjts='';
var sjsign='';
var outuser='';
var sourcelink='';
var outsign='';
var sourceurl = '';
var sourcename="";
var isSimple='';
var jiFenBao=0;var cAlipayAccount="";
var isRunning=1;
var SJBack='';var jiFen="0";
var FromSj=0;
var ItemDicData="";
var rndnum="3716597092.77891453";
var totalPage=1;
var totalCut=0;
var cepingCandidate="";
var allowPart=0;
var cpid="";
var needSaveJoin=0;
var isChuangGuan=0;
var jqnonce="4836f1d3-e5ad-42fa-a99f-48809b83a20a";
var maxCgTime=0;
var maxOpTime=0;
var qBeginDate="1573528025483";
var randomMode=0;
var fisrtLoadTime=new Date().getTime();
var canAward=1;
var allowAward=1;
var isVip=0;
var LogStoreLocal=0;
var needLogCompanyId=0;
var needHBAlert=0;
var isPromoteing=0;
var prsjts = "";
var prsjsign = "";
var cityPeiEQues = "";
if(needHBAlert && !window.needLogin){
if(needHBAlert==-1){
var hbmsg=$("#spanTip").text();
alertNew(hbmsg);
}
else if(needHBAlert==-2)
alertNew("请注意:抽中红"+"包后答卷还需要发布者审核,通过审核后才能发放红"+"包!");
else if(needHBAlert==-4){
var hbmsg=$("#spanTip").text();
alertNew(hbmsg);
}
else if(needHBAlert<0){
alertNew("请注意:每个参与者填完问卷后有"+(needHBAlert*-1)+"%的概率抽中红"+"包");
}
else
alertNew("请注意:每个参与者填完问卷后有1/" + needHBAlert + "的概率抽中红"+"包");
}
var needAwardAlert=0;
var leftSeconds=0-10;
if(needAwardAlert && !window.needLogin){
var divawardalert=document.getElementById("divawardalert");
var awt=$.trim($(divawardalert).text());
if(awt)
alert(awt);
}
var hasChuangGuanEnd=false;
var IsPar=0;
var curProvince="";
var curCity="";
var curIp="221.176.33.49";
var curFuHe=0;
var curCheckResult=0;
var addtoHis=0;
var isForein=0;
</script>
<script type="text/javascript">
var needAvoidCrack=0;
var tdCode="tdCode";
var imgCode = $("#imgCode")[0];
var submit_text = $("#yucinput")[0];
var tCode = $("#"+tdCode)[0];
var hasTouPiao =0
</script>
<div style="display: none;">
<script src="https://s13.cnzz.com/z_stat.php?id=4478442&web_id=4478442" language="JavaScript" async="" onload="if(window.loadCzc)loadCzc();"></script>
<script>var _hmt = _hmt || [];(function() {var hm = document.createElement("script");hm.src = "https://hm.baidu.com/hm.js?21be24c80829bd7a683b2c536fcf520b";var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s);})();</script>
</div>
<script>
function loadCzc(){
if (window._czc) {
var evvtype="免费版";if(isVip)evvtype="企业版";
_czc.push(["_trackEvent", "移动端JQ", evvtype, cqType]);
if (window.isQywx) {
_czc.push(["_trackEvent", "企业微信", "打开问卷", ""]);
}
}
}
</script>
<script>
var awardkeylist="1§JLPT,JTEST,J.TEST,CATTI,50音,日语,韩语,Japan,Japanese,cosplay,の,な,ん,い,う,こ,し,せ,て,た,GRE,GMAT,offer,toefl,IELTS,LSAT,TEF§0┋2§美妆,化妆,护肤,小红书,HPV,内衣,玻尿酸,射频仪,肌肤测试,美容仪,瘦脸针,肉毒杆菌§1┋3§GRE,雅思,托福,G5,SAT,SSAT,ACTGMAT,jlpt,offer,toefl,IELTS,LSAT,TEF§1┋4§高中生,高一,高二,高三,高1,高2,高3,高中家长,高考§4┋5§初中生,初一,初二,初三,七年级,八年级,九年级,初1,初2,初3,7年级,8年级,9年级,中考,初升高§5┋7§小学生,附小,小学,小学家长,一年级,二年级,三年级,四年级,五年级,六年级,少先队,少先大队,1年级,2年级,3年级,4年级,5年级,6年级,小升初,低年级,口算,儿童节§7┋8§幼儿园,幼儿家长,园家长,大班,中班,大一班,大二班,大三班,小班幼儿,绘本,学前教育,学前儿童,早教,幼教中心,智力开发,睡前故事,蒙氏,积木,乐高,启蒙,拼音,幼儿,少儿,儿童,早教,幼稚园,幼教,育儿§8┋9§中学,中学生,中小学,附中,国际学校,中一班,中二班,中三班§6┋10§益智,托管所,托儿所,推车,童车,安全座椅,积木,巧虎,乐智小天地,§10┋11§家长,亲子,家教,孩子,家庭教育,共育,父母§11┋12§家访,培优,奥数,高年级,中年级,课堂作业,课后作业,家庭作业,苏教版,加减法,尖子班,人教版,提高班,青春期,冬令营,夏令营,课业,升学,考级,学籍,课外辅导,义务教育,补习,叛逆期,课业负担,提高班,校服§9┋13§大一,大二,大三,大四,考研,应届,奖学金,选修课,学生会,大学生,恋爱观,就业,择业,支教,打工,实习,留学生§2┋14§小语种,翻译,口译,外语,外教,听力,语种,真题,考研,口语,词汇,六级,英语,词汇,语法,the,and,that,for§12┋15§出国,部门,大区,职工,工号,跨国企业,国贸,报关,外贸,外企,海外,境外,国际部,签证,跨境,国际,航空,出境,空乘,进口,出口,海外,乘务,报关,外贸,外企,海外,境外,签证,跨境,出境,进口,出口,金融,出国,国贸,跨国企业,跨国公司,合资,出国,汽车,商城,酒店,购物,商场,商店,酒,咖啡,VIP,高尔夫,邮轮,相机,投资,炒股,股票,股市,金融,理财,财经,基金,财经,奢侈品,集团,企业,公司,员工,工会,旅游,旅行,购车,航班,证券,保险,银行,高层,部门,别墅,4S,红酒,财富,财务,高端,考察,海淘,海外,私募,贷款,私教,干红,健身,出境,境外,私家,ETC,车友,购房,房产,融资,花园,洋房,招商,地产,越野,轿车,度假,经理,总裁,研修,总监,私家车,会所,贵宾,MBA,物业,mall§14┋17§学历,受教育程度§3┋18§车位,车辆保养,4s店,车牌号,驾驶证,驾照,车险§1";
var qukeylist="";
var currJT=2;
var isMobileFile =1;
</script>
</body>
</html>
版权声明:本文为weixin_41459547原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。