Raw Source
hahazhoutie4 / 知享网刷题工具-试题练习

// ==UserScript==
// @name         知享网刷题工具-试题练习
// @namespace    http://tampermonkey.net/
// @version      2024-07-10
// @description  boom!boom!
// @author       tony_chow
// @match        https://kolshare-3burszgc.cscec3b-iti.com/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=cscec3b-iti.com
// @updateURL    https://openuserjs.org/meta/hahazhoutie4/practice_data.meta.js
// @downloadURL  https://openuserjs.org/src/scripts/hahazhoutie4/practice_data.user.js
// @license      MIT
// @grant        GM_registerMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// ==/UserScript==
(function() {
    'use strict';
    var prac_number = 5 ; //抽取5套题目
    //改为本地存储 var json_data = new Object();       //试题练习答案集
    //改为本地存储 json_data = JSON.parse("{}");       //试题练习答题全部选A并返回答案answer

    //试题练习--提交并获取答案
    function ans(itemBankId,testPracticeItemId){
        var time_ = new Date().getTime();
        var editAnswer ="A";
        if(GM_getValue(itemBankId)){
           editAnswer = GM_getValue(itemBankId);
           }
        $.ajax({
            async: false,
            url: 'https://kolshare-3burszgc.cscec3b-iti.com/college/api/test/testTestSave.do?_t='+time_+'&testPracticeItemId='+testPracticeItemId+'&editAnswer='+editAnswer+'&_t='+time_,
                //https://kolshare-3burszgc.cscec3b-iti.com/college/api/test/testTestSave.do?_t=1720585279589&testPracticeItemId=746289&editAnswer=A&_t=172058527
            type: 'GET',
            data : {},
            dataType: 'json',
            timeout: 30000,
            success: function(e){
               //改为本地存储 json_data[e.data.itemBankId] = e.data.answer;
                GM_setValue(e.data.itemBankId,e.data.answer);
              //调试  console.log(e.data.itemBankId,e.data.answer);
            },
            error: function(e){console.log(e);},
            complete: function(e){//console.log(e);
            },
        })
    }

    // 试题练习--延时函数
    function sleep(t) {
        var start =(new Date()).getTime();
        while((new Date()).getTime()-start<t){
            continue;
        }
    }

    //试题练习程序入口
    function init_b(){
        var i =0 ;
        while(i <prac_number){
            b();
            sleep(1000); //暂停1s
            i++; //执行prac_number套题目
        }
    }

    //试验答题,获取分数
    function getV(id){
       var time =new Date().getTime();
        $.ajax({
         async: false,
            url: 'https://kolshare-3burszgc.cscec3b-iti.com/college/api/test/testTestEnd.do?_t='+time+'&id='+id+'&_t='+time,
                //https://kolshare-3burszgc.cscec3b-iti.com/college/api/test/testTestEnd.do?_t=1720614681981&id=25128&_t=1720614681981
            type: 'GET',
            data : {},
            dataType: 'json',
            timeout: 30000,
            success: function(e){
                console.log("本次得分"+e.data.fraction);
                if(e.data.fraction>80){
                    alert("答题达到80分,给1分");   //弹窗告诉给80分。
                }
            },
            error: function(e){console.log(e);},
            complete: function(e){//console.log(e);
            }
        })
    }

    // 试验答题,获取题目
    function b(){
        var time = new Date().getTime();
        $.ajax({
            async: false,
            url: 'https://kolshare-3burszgc.cscec3b-iti.com/college/api/test/testTestSta.do?_t='+time+'&businessType=%E5%95%86%E5%8A%A1&majorType=%E9%80%9A%E7%94%A8&_t='+time,
            // https://kolshare-3burszgc.cscec3b-iti.com/college/api/test/testTestSta.do?_t=1720613162702&businessType=%E5%95%86%E5%8A%A1&majorType=%E9%80%9A%E7%94%A8&_t=1720613162702 商务 通用题库
            type: 'GET',
            data : {},
            dataType: 'json',
            timeout: 30000,
            success: function(e){
                var i = e.data.tpiList; // e.data.testPractice.tpiList[0-29].
                $.each(i,function(k,v){
                    ans(v.itemBankId,v.id); //题目的testPracticeItemId
                });
                     getV(e.data.id); //获取本次答题分数
              //  console.log(json_data);
            },
            error: function(e){console.log(e);},
            complete: function(e){//console.log(e);
            }
        });
    }
    GM_registerMenuCommand("试题练习",init_b,"h"); //试题练习
    // Your code here...
})();