webwork_extension

Adds correct ratio to each homework.

目前為 2019-12-06 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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

(async function() {
    async function getGrade(links) {
        let ans = "";
        for(let i = 0; i < links.length; i ++) {
            let st = String(links[i]);
            let id = st.indexOf("grades");
            if(id != -1) ans = st;
        }

        let map = {};
        let text = await fetch(ans);
        text = await text.text();
        for(let i = 0; i < text.length; i ++) {
            if(text[i] == '%') {
                let a = i - 1;
                while(text[a] != '>') a --;
                let b = a;
                while(text.substr(b, "</a>".length) != "</a>") b --;
                let c = b;
                while(text[c] != '>') c --;
                map[text.substr(c + 1, b - c - 1)] = text.substr(a + 1, i - a);
            }
        }
        return map;
    }
    let map = await getGrade(document.links);
    let text = document.body.textContent;
    let target = "open";
    let GG = "will";
    for(let i = 0; i < text.length - target.length; i ++) {
        if(text.substr(i, GG.length) == GG) i += 20;
        if(text.substr(i, target.length) == target) {
            let j = i - 2;
            while(text[j] != ' ') j --;
            let homeworkID = text.substr(j + 1, i - j - 2);
            if(homeworkID in map) {
                let re = new RegExp(">" + homeworkID + "<", 'g');
                document.body.innerHTML = document.body.innerHTML.replace(re, ">" + homeworkID + "</a><a = style=\"color:DodgerBlue;\">  " + map[homeworkID] + "<");
            }
        }
    }
})();