Adds correct ratio to each homework.
当前为
// ==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] + "<");
}
}
}
})();