Greasy Fork

乐学增强

增加AC,WA标志

当前为 2017-11-02 提交的版本,查看 最新版本

// ==UserScript==
// @name         乐学增强
// @namespace    YinTianliang_i
// @version      0.1
// @description  增加AC,WA标志
// @author       Yin Tianliang
// @include      *//online.bit.edu.cn/moodle/course/view.php*
// @grant        none
// ==/UserScript==

/*jshint esversion: 6 */

problem_list = document.getElementsByClassName("activity programming modtype_programming");

if (!localStorage.AC) {
    window.localStorage.AC = "";
}

for (let problem of problem_list) {
    let problem_id = problem.id.split("-")[1];
    let dstDiv = problem.firstChild.firstChild.firstChild;

    //有些题目没有没对齐不能忍
    if (dstDiv.className == "mod-indent") {
        dstDiv.className += " mod-indent-1";
    }

    if (window.localStorage.AC.indexOf(problem_id) == -1) {
        $.post(`http://online.bit.edu.cn/moodle/mod/programming/result.php?id=${problem_id}`,
            null, res => {
                matches = res.match(/未能通过的有 *(\d)* *个/);
                if (matches) {
                    if (matches[1] == "0") {
                        window.localStorage.AC += "|" + problem_id;
                        dstDiv.innerHTML = '<div style="color:green"><b>AC</b></div>';
                    } else {
                        dstDiv.innerHTML = '<div style="color:red"><b>WA</b></div>';
                    }
                }
            });
    } else {
        dstDiv.innerHTML = '<div style="color:green"><b>AC</b></div>';
    }
}