JavaScript-- automatically fill in the questionnaire Star

I. Introduction:

  Our school to brush academic chapter, some academic chapter is designated to fill in the questionnaire star at some point questionnaire registration. But because of my hand speed is slow, resulting in some cases do not always report the name, so the thinking put forward a code that automatically fill in the registration form questionnaire Star. After the meal operation, we found a more appropriate source on github, modified some code that can be achieved automatically fill in the questionnaire Star! Reference Address: https://github.com/wkmyws/wjxJS

  Bloggers environment: win10 64 + Google browser

   To achieve run on the browser javascript code, there are two ways:

  ① direct F12 to open the console in the questionnaire Star page, then paste the javascript code written in advance console, and press Enter to run! However, this method is slow, less desirable (because every time you want to turn on the questionnaire Star Field filled, then go turn on the console, and then paste, then ......, have had a lot of time, perhaps others have submitted the completed o (╥﹏╥) o)

  ② oil Hou script insertion in Google Chrome, the browser can automatically run js script. This method is fast, stable effect, using the following test method!

Second, test configuration +

1. Google browser plug oil Hou script

1.1 Oil Hou script is a free browser extension and most popular User Script Manager enhances user control over the browsing experience. Oil Hou script Download: http://www.tampermonkey.net/

1.2 installation process:

  ① in the upper right corner to open the browser chrome vertical three -> More Tools -> Extensions

  ② In the extension page, turn on developer mode

  ③ Click Load unpacked extensions, select the file after the download, unzip the folder

  

    Note: After the download, unzip oil Hou script best not to put Google browser's default extension position, otherwise restart oil Hou script may be cleared browser! Recommended oil Hou script file in a custom location!

  ④ After installation is complete, Google will display the top right corner of the browser oil Hou script icon

  

   

Problems encountered 1.3

After Google browser plug oil Hou script, the browser may appear repeatedly states the following:

解决办法:Chrome75及以上版本就不能彻底禁用了,参考这个 https://www.52pojie.cn/thread-988783-1-1.html 网址后,找到了解决办法。经测试,谷歌浏览器77版本也可以成功禁用这个弹窗!

简单说就是将下载的version.dll插件直接放在Chrome.exe同目录下即可解决问题!

version.dll下载链接:https://pan.baidu.com/s/1m-1NRK9lws599sBHp4iDIg
提取码:mc7x 

2. 测试

2.1 自动填写问卷星

1.测试代码如下:(支持问卷星的input、radio、checkbox,仅支持填写)

// ==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=[
        ["蛋片鸡",/(姓名)|(名字)/],
        ["18711111",/(学号)/],
        ["单选框_性别",/(性别)/,/(男)|(男生)/],
        ["单选框_年级",/(年级)/,/(18级)|(2018级)/],
        ["机自学院",/(学院)/],
        ["计算机",/(专业)/],
        ["11011001100",/(联系方式)|(电话)|(手机)|(手机号)/],
        ["[email protected]",/(QQ)|(qq)/]
    ];
    const ini={
        module:".div_question",//每个问题模块
        title:".div_title_question",//标题
        type:{
           "input_text":".inputtext",
           "radio":".ulradiocheck",
           "checkbox":".ulradiocheck"
        }
    };
    $(document).ready(function(){
        let itemNum = 0;
        $(ini.module).each(function(){
            itemNum += 1;
            let title=$(this).find(ini.title).text();
            //判断类别
            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":
                               case "checkbox":
                                   $(this).find("li").each(function(){
                                       if(info[i].length>=3&&info[i][2].test($(this).text())){
                                           $(this).find("a").click();
                                       }
                                   });
                                   break;
                               default:console.log("ini.type中没有匹配"+tp+"的键值");
                           }
                           break;
                       }
                   }
                    break;
                }
            }
        });
    });
})();

2.测试结果:

测试使用的问卷星链接:https://www.wjx.top/jq/46606239.aspx

2.2 自动填写并提交问卷星

1.测试代码如下:(支持填写并提交功能)

// ==UserScript==
// @name         问卷星测试——支持input radio checkbox
// @version      1.1
// @description  测试
// @author       FHC
// @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=[
        ["蛋片鸡",/(姓名)|(名字)/],
        ["18711111",/(学号)/],
        ["单选框_性别",/(性别)/,/(男)|(男生)/],
        ["单选框_年级",/(年级)/,/(18级)|(2018级)/],
        ["机自学院",/(学院)/],
        ["计算机",/(专业)/],
        ["11011001100",/(联系方式)|(电话)|(手机)|(手机号)/],
        ["[email protected]",/(QQ)|(qq)/]
    ];
    const ini={
        module:".div_question",//每个问题模块
        title:".div_title_question",//标题
        type:{
           "input_text":".inputtext",
           "radio":".ulradiocheck",
           "checkbox":".ulradiocheck"
        }
    };
    $(document).ready(function(){
        let itemNum = 0;
        $(ini.module).each(function(){
            itemNum += 1;
            let title=$(this).find(ini.title).text();
            //判断类别
            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":
                               case "checkbox":
                                   $(this).find("li").each(function(){
                                       if(info[i].length>=3&&info[i][2].test($(this).text())){
                                           $(this).find("a").click();
                                       }
                                   });
                                   break;
                               default:console.log("ini.type中没有匹配"+tp+"的键值");
                           }
                           break;
                       }
                   }
                    break;
                }
            }
        });
        $('.submitbutton').click();
    });
})();

 

 其实上面就是增加了一行代码就可以进行问卷提交!

2.测试结果:

测试使用的问卷星链接:https://www.wjx.top/jq/46606239.aspx

 

 

 

Guess you like

Origin www.cnblogs.com/FHC1994/p/11721723.html
Recommended