Bypass "Calculation of totals has been disabled" for canvas

Calculates totals when canvas doesn't want to

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Bypass "Calculation of totals has been disabled" for canvas
// @namespace   https://boehs.org
// @match       https://*.instructure.com/courses/*/grades
// @grant       none
// @version     1.1.0
// @author      Evan Boehs
// @description Calculates totals when canvas doesn't want to
// @supportURL  https://gist.github.com/boehs/883fda113facb902ac440cab26b09cb9
// @license     GPL-3.0-only
// ==/UserScript==

function update() {
  let totalCurrent = 0
  let totalPossible = 0
  const assignments = document.querySelectorAll("tr.student_assignment:not(.group_total)")
  assignments.forEach(assignment => {
    const possible = Number((assignment.querySelector(".possible.points_possible").textContent || "").trim())
    const current = Number((assignment.querySelector(".assignment_score .grade").textContent.replace(/((hat-)|[^0-9-.])/g,"") || "").trim())
    if (!isNaN(possible + current)) {
      totalPossible += possible
      totalCurrent += current
    }
  })
  const percent = ((totalCurrent / totalPossible) * 100).toFixed(2)
  
  document.getElementById("student-grades-final").innerHTML = `${percent}% <sub>
  <span>(Bypassed)</span>
  <br/>
  <span>NOTE: This script does not support weights yet</span>
  </sub>`
}

if (document.getElementById("student-grades-final").textContent.trim() == 'Calculation of totals has been disabled') {
  const observer = new MutationObserver(update)
  
  observer.observe(document.getElementById("grades_summary"), { childList:true, subtree:true })
  
  update()
}