Colorful Course

Try and see

目前为 2022-12-11 提交的版本。查看 最新版本

// ==UserScript==
// @name         Colorful Course
// @namespace    http://tampermonkey.net/
// @version      0.2.1
// @description  Try and see
// @author       Ajax
// @match        http://zhjwxk.cic.tsinghua.edu.cn/xkBks.vxkBksXkbBs.do?m=xkqkSearch*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tsinghua.edu.cn
// @grant        none
// @license      MIT
// ==/UserScript==

function colorOne(td, sum, available) {
    var l = td.text.split(",");

    if (l[0][0] === '(') {
        l = l[0].substr(1, l[0].length - 1).split(")").concat(l.slice(1));
    }

    var html = "";
    for (var i=0; i<l.length; ++i) {
        l[i] = Number(l[i]);

        if (sum > available) {
            html += `<span style="color:red">${l[i]}</span>,`;
        }
        else if ((sum += l[i]) > available) {
            html += `<span style="color:orange">${l[i]}</span>,`;
        }
        else {
            html += `<span style="color:green">${l[i]}</span>,`;
        }
    }

    td.innerHTML = html.substr(0, html.length - 1);
    return sum;
}

function setOneWidth(tr) {
    /*
    tr.children[0].setAttribute("width", "70");
    tr.children[1].setAttribute("width", "40");
    tr.children[2].setAttribute("width", "440");
    tr.children[3].setAttribute("width", "70");
    tr.children[4].setAttribute("width", "50");
    tr.children[5].setAttribute("width", "50");
    tr.children[6].setAttribute("width", "100");
    tr.children[7].setAttribute("width", "100");
    tr.children[8].setAttribute("width", "100");
    */
}

(function() {
    'use strict';

    var regular = document.getElementsByName("top")[0];

    setInterval(function() {
        var doc = regular.contentDocument;

        if (doc.colored === true) {
            return;
        }

        setOneWidth(doc.getElementsByClassName("trr1")[0]);

        doc.getElementsByClassName("trr2").forEach((tr) => {

            setOneWidth(tr);

            var available = Number(tr.children[4].text);
            var total = Number(tr.children[5].text);
            var sum = 0;

            sum = colorOne(tr.children[6], sum, available);
            sum = colorOne(tr.children[7], sum, available);
            sum = colorOne(tr.children[8], sum, available);
        });

        doc.colored = true;
    }, 1000);

    var pe = document.getElementsByName("bottom")[0];

    setInterval(function() {
        var doc = pe.contentDocument;

        if (doc.colored === true) {
            return;
        }

        doc.getElementsByClassName("trr2").forEach((tr) => {
            var available = Number(tr.children[3].text);
            var total = Number(tr.children[4].text);
            var sum = 0;

            sum = colorOne(tr.children[5], sum, available);
        });

        doc.colored = true;
    }, 1000);
})();

QingJ © 2025

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