BuaaGsmisTool

查看选课系统的班级容量, 修复已选课无法查看详情bug

Verze ze dne 16. 02. 2020. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         BuaaGsmisTool
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  查看选课系统的班级容量, 修复已选课无法查看详情bug
// @author       [email protected]
// @match        http://gsmis.buaa.edu.cn/qdwebpages/index.html*
// @match        https://gsmis.e.buaa.edu.cn/qdwebpages/index.html*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
        var css = ".Course-name h3 { z-index: 100;}",
        head = document.head || document.getElementsByTagName('head')[0],
        style = document.createElement('style');
    style.type = 'text/css';
    if (style.styleSheet) {
        // This is required for IE8 and below.
        style.styleSheet.cssText = css;
    } else {
        style.appendChild(document.createTextNode(css));
    }
    head.appendChild(style);
    
    // https://dmitripavlutin.com/catch-the-xmlhttp-request-in-plain-javascript/
    var open = window.XMLHttpRequest.prototype.open,
        send = window.XMLHttpRequest.prototype.send;

    function openReplacement(method, url, async, user, password) {
        this._url = url;
        return open.apply(this, arguments);
    }

    function sendReplacement(data) {
        if (this.onreadystatechange) {
            this._onreadystatechange = this.onreadystatechange;
        }
        this.onreadystatechange = onReadyStateChangeReplacement;
        return send.apply(this, arguments);
    }

    function onReadyStateChangeReplacement() {
        var resp = this._onreadystatechange.apply(this, arguments);

        var that = this;
        setTimeout(function () {

            if (that.readyState === 4 && that.status === 200 && that._url.startsWith('/api/yuXuanKeApiController.do?findKcxxList')) {
                var res = JSON.parse(that.responseText);

                var courses = document.getElementsByClassName('Course-name');
                //console.log(courses);
                for (var i = 0; i < courses.length; i++) {
                    var info = res['attributes']['kclb'][i];
                    var curr = courses[i];
                    var p = curr.getElementsByTagName('p');
                    if(p[0].innerText.indexOf(info['kch'])===-1){
                        console.warn("BuaaGsmisTool脚本遇到错误,无法找到当前课程的可选人数",info['kch'],p[0].innerText);
                    }else{
                        for(var idx in p)
                            if(p[idx].innerText.indexOf('已预选')!==-1){
                                p[idx].innerText = '已预选/总:' + info['dqyxrs'] + '/' + info['kxrs'];
                                break;
                            }
                    }
                }
            }
        }, 200);

        return resp;
    }

    window.XMLHttpRequest.prototype.open = openReplacement;
    window.XMLHttpRequest.prototype.send = sendReplacement;
})();