Bypass "Calculation of totals has been disabled" for canvas

Calculates totals when canvas doesn't want to

当前为 2022-09-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Bypass "Calculation of totals has been disabled" for canvas
  3. // @namespace https://boehs.org
  4. // @match https://*.instructure.com/courses/*/grades
  5. // @grant none
  6. // @version 1.0.1
  7. // @author Evan Boehs
  8. // @description Calculates totals when canvas doesn't want to
  9. // @supportURL https://gist.github.com/boehs/883fda113facb902ac440cab26b09cb9
  10. // @license GPL-3.0-only
  11. // ==/UserScript==
  12.  
  13. function update() {
  14. let totalCurrent = 0
  15. let totalPossible = 0
  16. const assignments = document.querySelectorAll("tr.student_assignment:not(.group_total)")
  17. assignments.forEach(assignment => {
  18. const possible = Number((assignment.querySelector(".possible.points_possible").textContent || "").trim())
  19. const current = Number((assignment.querySelector(".assignment_score .grade").textContent.replace(/((hat-)|[^0-9-])/g,"") || "").trim())
  20. if (!isNaN(possible + current)) {
  21. totalPossible += possible
  22. totalCurrent += current
  23. }
  24. })
  25. const percent = (totalCurrent / totalPossible) * 100
  26. document.getElementById("student-grades-final").innerHTML = `${percent}% <sub>
  27. <span>(Bypassed)</span>
  28. <br/>
  29. <span>NOTE: This script does not support weights yet</span>
  30. </sub>`
  31. }
  32.  
  33. if (document.getElementById("student-grades-final").textContent.trim() == 'Calculation of totals has been disabled') {
  34. const observer = new MutationObserver(update)
  35. observer.observe(document.getElementById("grades_summary"), { childList:true, subtree:true })
  36. update()
  37. }