BuaaGsmisTool

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

目前為 2020-02-12 提交的版本,檢視 最新版本

// ==UserScript==
// @name         BuaaGsmisTool
// @namespace    http://tampermonkey.net/
// @version      0.4
// @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');
                for (var i = 0; i < courses.length; i++) {
                    var info = res['attributes']['kclb'][i];
                    var curr = courses[i];
                    var p = curr.getElementsByTagName('p');
                    for (var k =  p.length-1; k >=0; k--) {
                        if (p[k].innerHTML.startsWith('当前已预选人数')) {
                            p[k].innerHTML = '已预选/总:' + info['dqyxrs'] + '/' + info['kxrs'];
                            break;
                        }
                    }
                }
            }
        }, 500);

        return resp;
    }

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址