webwork_extension

Adds correct ratio to each homework.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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);
    });
})();