webwork_extension

Adds correct ratio to each homework.

  1. // ==UserScript==
  2. // @name webwork_extension
  3. // @namespace webwrok.math.ntu.edu.tw
  4. // @version 2.0
  5. // @description Adds correct ratio to each homework.
  6. // @author bert30702, oToToT
  7. // @match *://*.webwork.math.ntu.edu.tw/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (async function(){
  12. function getGrade(html_text){
  13. var m = {};
  14. let d = new DOMParser();
  15. let doc = d.parseFromString(html_text, 'text/html');
  16. let nodes = doc.querySelectorAll("#grades_table tr:not([class=grades-course-total])");
  17. nodes.forEach(function(ele) {
  18. let e = ele.getElementsByTagName('td');
  19. if (e.length) m[e[0].innerText]=e[1].innerText;
  20. })
  21. return m;
  22. }
  23. let grades_html = await (await fetch("grades/")).text();
  24. let map = getGrade(grades_html);
  25. document.querySelectorAll('a[class=set-id-tooltip]').forEach(function(ele) {
  26. // to hide score in closed problems, please uncomment the statement below
  27. // if (ele.parentNode.parentNode.innerText.includes('closed')) return;
  28. let key = ele.innerText;
  29. let span = document.createElement("span");
  30. span.innerText = ` ${map[key]}`;
  31. switch (map[key]) {
  32. case '100%':
  33. span.style.color = '#008000';
  34. break;
  35. case '0%':
  36. span.style.color = '#ff0000';
  37. break;
  38. default:
  39. span.style.color = '#1e90ff';
  40. }
  41. ele.parentNode.appendChild(span);
  42. });
  43. })();