北理工乐学增强

增强北理工乐学的功能

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

// ==UserScript==
// @name         北理工乐学增强
// @namespace    YinTianliang_i
// @version      0.3
// @description  增强北理工乐学的功能
// @author       Yin Tianliang
// @include      *//online.bit.edu.cn/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

/*jshint esversion: 6 */

if (/course\/view.php\?id=\d+/.test(window.location.toString())) {
    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>';
        }
    }

    // 增加 "自己的AC数"
    // 待优化
    table = document.getElementsByClassName('generaltable')[1].children[1];
    table.insertRow(0);
    table.children[0].insertCell(0);
    table.children[0].insertCell(1);
    table.children[0].insertCell(2);
    table.children[0].children[0].textContent = '0';
    table.children[0].children[1].textContent = 'Your';
    table.children[0].children[2].textContent = window.localStorage.AC.split('|').length;
}

// 隐藏 上传文件 
if (/programming\/submit.php\?id=\d+/.test(window.location.toString()))
    document.getElementsByClassName('fitem fitem_ffilepicker')[0].style = 'display:none'