校情与教学质量问卷自动化(GXMU)

自动完成调查问卷

目前為 2023-06-25 提交的版本,檢視 最新版本

// ==UserScript==
// @name         校情与教学质量问卷自动化(GXMU)
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  自动完成调查问卷
// @author       叶月绘梨依
// @match        http://210.36.48.43/new/student/rank/evaluate2.jsp*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=48.43
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    var all_tasks;
    var all_links;
    var isload=0;
    //关闭对话框
    function fclose(){
        var gcloses=document.querySelectorAll("button[data-dismiss='modal'].blue");
        for(let i=0;i<gcloses.length;i++){
            try{ gcloses[i].click();}catch(e){console.log("some error happened when try to find the function which enbale to close the modal...");}
         }
    }

    setTimeout(function(){
        all_tasks=document.querySelectorAll("td>span.badge-important,td>span.badge-success");
        //console.log(all_tasks);
        all_links=document.querySelectorAll("td>div.tdrepaire>a[onclick].blue");
        //console.log(all_links);

        var undone=[];
        for(let i=0;i<all_tasks.length;i++){
            var badge_class=all_tasks[i].getAttribute("class");
            //console.log(badge_class);
            if(badge_class=="badge badge-important"){
                undone.push(i);
            }
        }

        var count=0;
        console.log(undone);
        if(undone.length==0){
            alert("所有评测已经完成!");
        }
        else{
            var inter=setInterval(function(){
            if(count==undone.length){
                clearInterval(inter);
                fclose();
                alert("所有评测已经完成!");
            }
            all_links[undone[count]].click()
            count++;
            //找到所有选项(10分..0分)
            var opts=document.querySelectorAll("label.radio>div>span");
            //筛选出10分的选项,自动选择10分的选项
            for(let i=0;i<opts.length;i++){
                var op=opts[i].querySelector("input");
                if(op.value=="10"||op.value=="1"){
                    var item=opts[i].parentNode.parentNode;
                    item.dispatchEvent(new MouseEvent("click"));
                }
            }

            //由于问卷不能满分,所以倒数第11题固定选第二个
            opts[opts.length-9].parentNode.parentNode.dispatchEvent(new MouseEvent("click"));

            //点击提交按钮
            var submit=document.getElementById("pjsubmit");

            //关闭按钮
            submit.click();
            fclose();
         },400);
        }
     },2000)

})();