2CLASS抢课

CQUT2课抢课脚本。需进行端口监听使用!

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         2CLASS抢课
// @namespace    https://ehall.cqut.edu.cn/
// @version      1.5
// @description  CQUT2课抢课脚本。需进行端口监听使用!
// @author       KerCaR QQ78053394
// @match         *://2class.cqut.edu.cn/Student/Activity/apply.html*
// @icon         https://www.cqut.edu.cn/
// @grant        none
// @require      https://cdn.bootcss.com/html2canvas/1.4.1/html2canvas.min.js
// @license      MIT
// ==/UserScript==
(function() {
    var Period = 300;//抢课的时间间隔 300ms,不建议低于200ms
    var AutoExit = true;//完成后是否自动退出
    var refreshTimer = setInterval(function()
    {
         window.scrollTo(0, document.body.scrollHeight);//滚到底部
         var flag1=document.getElementsByClassName("baom disabled")[0];
         if(flag1!=null&&flag1.innerText=="已报名"&&AutoExit==true) {window.close();}
         if(flag1!=null&&flag1.innerText=="未开始")
         {
             document.cookie = "activityApplyTimes=1";
             location.reload();
         }
        else
        {
          var width = 90;
          var height = 35;
          html2canvas(document.getElementById("vcode"), {
              width: width,
              height: height,
              scale: 1,
              useCORS: true,
              logging: true
            }).then(function(canvas) {
                  var result = recognizeCaptcha(canvas.toDataURL('image/png'), function(result) {
                  console.log(result.data);
                  var input = document.querySelector('input');
                  input.value=result.data;
                  document.getElementById("ok").click();
                  var btn=document.querySelector('span.mui-popup-button');
                  mui.trigger(btn,'tap');
                  document.cookie = "activityApplyTimes=1";
              });
              location.reload()
           });
       }
    },Period);
    var recognizeCaptcha = function(src, callback)//与本地监听端口通信,发送图片,获得验证码
    {
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "http://127.0.0.1:19199/runtime/text/invoke", true);
        xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
        xhr.onload = function() {
            if (xhr.status === 200) {
                callback(JSON.parse(xhr.responseText));
            } else {
                console.error("请求发生错误:", xhr.status);
            }
        };
        xhr.onerror = function() {
            console.error("请求发生错误:", xhr.status);
        };
        var data = JSON.stringify({"project_name": "ddddocr","image": src,"extra": {"label_map":["0","1","2","3","4","5","6","7","8","9"]}});
        xhr.send(data);
    }
})();