Created
January 12, 2023 22:46
-
-
Save amatzen/6ba318be31fba457ca52e79f9adeba5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name SDU GPA Calculator | |
// @namespace https://alexander.dk/ | |
// @version 0.1 | |
// @description | |
// @author You | |
// @match https://selvbprod.sdu.dk/prod/sb/resultater/studresultater.jsp | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=sdu.dk | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const GPA_CONVERSION_TABLE = { | |
'A': 5, | |
'B': 4, | |
'C': 3, | |
'D': 2, | |
'E': 1, | |
'F': 0 | |
} | |
const resultTable = document.querySelector("#resultTableGrup > tbody"); | |
const gradeNodes = resultTable.querySelectorAll("tr"); | |
const grades = []; | |
for(const gradeNode of gradeNodes) { | |
const gradeText = gradeNode.querySelector("td:nth-child(5)")?.textContent; | |
if (isNaN(gradeText)) continue; | |
const gradeEcts = gradeNode.querySelector("td:nth-child(6)")?.textContent; | |
const weightText = gradeNode.querySelector("td:nth-child(7)")?.textContent; | |
const grade = Number(gradeText); | |
const weight = Number(weightText); | |
grades.push({grade, weight, gradeEcts}); | |
} | |
const accWeights = grades.reduce((acc, next) => acc + next.weight, 0); | |
const gpaDK = grades.reduce((acc, next) => acc + (next.grade * next.weight), 0) / accWeights; | |
const gpaUS = grades.reduce((acc, next) => acc + (GPA_CONVERSION_TABLE[next.gradeEcts] * next.weight), 0) / accWeights; | |
resultTable.insertAdjacentHTML('beforeend', ` | |
<tr class="DataSelect"></tr> | |
<tr class="DataSelect"> | |
<td colspan="4" class="DataValue"><b>Vægtet gennemsnit (DK):</b></td> | |
<td colspan="3" class="DataValue">${gpaDK}</td> | |
</tr> | |
<tr class="DataSelect"> | |
<td colspan="4" class="DataValue"><b>Vægtet gennemsnit GPA (US):</b></td> | |
<td colspan="3" class="DataValue">${gpaUS}</td> | |
</tr> | |
`); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment