Raw Source
hahazhoutie4 / 知享网刷题工具-挑战答题

// ==UserScript==
// @name         知享网刷题工具-挑战答题
// @namespace    http://tampermonkey.net/
// @version      2024-07-10
// @description  try to take over the world!
// @author       tony_chow
// @updateURL    https://openuserjs.org/meta/hahazhoutie4/challenge_data.meta.js
// @downloadURL  https://openuserjs.org/src/scripts/hahazhoutie4/challenge_data.user.js
// @match        https://kolshare-3burszgc.cscec3b-iti.com/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=cscec3b-iti.com
// @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 json_d = new Object();    //挑战答题答案集    用GM_setValue、GM_getValue代替
  //    json_d = JSON.parse("{}");    //挑战答题答题全部选A并返回答案answer
  var indexNum = 1; //挑战答题题目成功数量= indexNum -1
  var max_count = 10; //限制挑战答题初始化最高次数

  //挑战答题-答题正确后刷新题目
  function refresh(item_challid) {
    var time = new Date().getTime();
    $.ajax({
      async: false,
      url: 'https://kolshare-3burszgc.cscec3b-iti.com/college/api/test/testChallengeNext.do?_t=' + time + '&_t=' + time,
      type: 'GET',
      data: {},
      dataType: 'json',
      timeout: 30000,
      success: function (e) {
        var bankid = e.data.itemBankId;
        fc(bankid, item_challid);
      },
      error: function (e) {
        console.log(e);
      },
      complete: function (e) { //console.log(e);
      }
    })
  }

  //挑战答题-回答问题并存储答案
  function fc(item_bankid, item_challid) {
    var time = new Date().getTime();
    var editAnswer = "A";
    if (GM_getValue(item_bankid)) {
      editAnswer = GM_getValue(item_bankid);
    }
    $.ajax({
      async: false,
      url: 'https://kolshare-3burszgc.cscec3b-iti.com/college/api/test/testChallengeSave.do?_t=' + time + '&id=' + item_challid + '&indexNum=' + indexNum + '&itemBankId=' + item_bankid + '&editAnswer=' + editAnswer + '&_t=' + time,
      type: 'GET',
      data: {},
      dataType: 'json',
      timeout: 30000,
      success: function (e) {
        var answer = e.data.answer; //返回的答案
        var isRight = e.data.int1; // 0为错,1为对
        console.log("回答是否正确" + isRight);
        GM_setValue(item_bankid, answer); //答案录入本地数据库
        //  json_d[item_bankid] = answer;  //录入正确答案
        if (isRight == 1) {
          indexNum++;
          if (indexNum > 5) {
            console.log("刷对5题");
            alert("给1分");
            return;
          }
          refresh(item_challid);
        }
        else {
          indexNum = 1; //挑战归零
          max_count--; //最高次数减1次
          console.log("重新挑战");
          init_c();
        }
      },
      error: function (e) {
        console.log(e);
      },
      complete: function (e) { //console.log(e);
      }

    })

  }

  //挑战答题-程序入口
  function init_c() {
    // 第一次访问试题 https://kolshare-3burszgc.cscec3b-iti.com/college/api/test/testChallenge.do?_t=1720602623421&_t=1720602623421
    // 答题  https://kolshare-3burszgc.cscec3b-iti.com/college/api/test/testChallengeSave.do?_t=1720604102852&id=221204&indexNum=1&itemBankId=218&editAnswer=A&_t=1720604102852
    // 下一题 https://kolshare-3burszgc.cscec3b-iti.com/college/api/test/testChallengeNext.do?_t=1720604103079&_t=1720604103079
    if (max_count < 1) {
      return;
    }
    var time = new Date().getTime();
    $.ajax({
      async: false,
      url: 'https://kolshare-3burszgc.cscec3b-iti.com/college/api/test/testChallenge.do?_t=' + time + '&_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) {
        var item_bankid = e.data.testExamItem.itemBankId; //题目的itembankid
        var item_challid = e.data.testChallenge.id; //用户的挑战id,用于发起挑战顺序流
        fc(item_bankid, item_challid); //提交答案
      },
      error: function (e) {
        console.log(e);
      },
      complete: function (e) { //console.log(e);
      }
    })
  }

  //试验答题,获取分数
  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);
      },
      error: function (e) {
        console.log(e);
      },
      complete: function (e) { //console.log(e);
      }
    })
  }

  GM_registerMenuCommand("挑战答题", init_c, "f"); //挑战答题
  // Your code here...
})();