webwork_extension

Adds correct ratio to each homework.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         webwork_extension
// @namespace    webwrok.math.ntu.edu.tw
// @version      2.0
// @description  Adds correct ratio to each homework.
// @author       bert30702, oToToT
// @match        *://*.webwork.math.ntu.edu.tw/*
// @grant        none
// ==/UserScript==

(async function(){
    function getGrade(html_text){
        var m = {};
        let d = new DOMParser();
        let doc = d.parseFromString(html_text, 'text/html');
        let nodes = doc.querySelectorAll("#grades_table tr:not([class=grades-course-total])");
        nodes.forEach(function(ele) {
            let e = ele.getElementsByTagName('td');
            if (e.length) m[e[0].innerText]=e[1].innerText;
        })
        return m;
    }
    let grades_html = await (await fetch("grades/")).text();
    let map = getGrade(grades_html);
    document.querySelectorAll('a[class=set-id-tooltip]').forEach(function(ele) {
        // to hide score in closed problems, please uncomment the statement below
        // if (ele.parentNode.parentNode.innerText.includes('closed')) return;
        let key = ele.innerText;
        let span = document.createElement("span");
        span.innerText = ` ${map[key]}`;
        switch (map[key]) {
            case '100%':
                span.style.color = '#008000';
                break;
            case '0%':
                span.style.color = '#ff0000';
                break;
            default:
                span.style.color = '#1e90ff';
        }
        ele.parentNode.appendChild(span);
    });
})();