webwork_extension

Adds correct ratio to each homework.

安装此脚本?
作者推荐脚本

您可能也喜欢Omnivox Auto Login

安装此脚本
  1. // ==UserScript==
  2. // @name webwork_extension
  3. // @namespace webwrok.math.ntu.edu.tw
  4. // @version 3.4
  5. // @description Adds correct ratio to each homework.
  6. // @author bert30702, oToToT, WengH
  7. // @match *://*.webwork.math.ntu.edu.tw/*
  8. // @match *://webwork.marianopolis.com/*
  9. // @match *://wwserver.marianopolis.com/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (async function(){
  14. function parseScore(str) {
  15. return parseFloat(str);
  16. }
  17. function round(f) {
  18. return Math.round(f * 10) / 10;
  19. }
  20. function getGrade(html_text) {
  21. var m = {};
  22. let d = new DOMParser();
  23. let doc = d.parseFromString(html_text, 'text/html');
  24. let nodes = doc.querySelectorAll("#grades_table tr:not([class=grades-course-total])");
  25. nodes.forEach(function(ele) {
  26. let e = ele.getElementsByTagName('td');
  27. if (e.length > 3) {
  28. m[e[0].innerText] = [parseScore(e[1].innerText), parseScore(e[2].innerText)];
  29. }
  30. });
  31. return m;
  32. }
  33. let grades_url = location.pathname + "/grades/";
  34. let grades_html = await (await fetch(grades_url)).text();
  35. let map = getGrade(grades_html);
  36. document.querySelectorAll('td a').forEach(function(ele) {
  37. // to hide score in closed problems, please uncomment the statement below
  38. // if (ele.parentNode.parentNode.innerText.includes('closed')) return;
  39. let key = ele.innerText;
  40. let span = document.createElement("span");
  41. if (!map[key]) return;
  42. let score = map[key][0];
  43. let total = map[key][1];
  44. if (total == 100) {
  45. span.innerText = ` ${score}%`;
  46. }
  47. else {
  48. span.innerText = ` ${round(score / total * 100)}% (${score} / ${total})`;
  49. }
  50. if (score >= total) {
  51. span.style.color = '#00a000'
  52. }
  53. else if (score === 0) {
  54. span.style.color = '#ff0000'
  55. }
  56. else if (score <= 0.6 * total) {
  57. span.style.color = '#c14900'
  58. }
  59. else {
  60. span.style.color = '#1e90ff'
  61. }
  62. ele.parentNode.appendChild(span);
  63. });
  64. })();