Skip to content

Instantly share code, notes, and snippets.

@Beyarz
Forked from xobust/Betygssnitt.py
Last active March 25, 2022 20:22
Show Gist options
  • Save Beyarz/656d64ded947498df4f6e54e19fe1ec2 to your computer and use it in GitHub Desktop.
Save Beyarz/656d64ded947498df4f6e54e19fe1ec2 to your computer and use it in GitHub Desktop.
Beräknar snittet av betygen från antagnig.se https://www.antagning.se/se/mypages/credentials
// ==UserScript==
// @name Merit
// @description Beräkna din merit
// @match https://*.antagning.se/se/mypages/credentials
// ==/UserScript==
'use strict';
const appendGrade = (gradeParam) => {
const injectionPoint = document.querySelector('[data-protractor-upsec-approved-points-4teinf]')
let gradeElement = document.createElement('p')
gradeElement.textContent = `Merit: ${gradeParam.toFixed(2)}`
injectionPoint.appendChild(gradeElement)
}
/**
* @return {number}
*/
const calc = () => {
const grades = {
'A': 20,
'B': 17.5,
'C': 15,
'D': 12.5,
'E': 10,
'F': 0
};
const subjects = document.querySelector('tbody').children
const merit = 2.0
const totalPoints = 2400
const gradeIndex = 2
const pointIndex = 3
var total = 0
Array.from(subjects, element => {
let grade = element.children.item(gradeIndex).textContent
let point = element.children.item(pointIndex).textContent
total += grades[grade] * point
});
var final = total / totalPoints + merit
console.log(`Din merit är: ${final}`)
appendGrade(final)
};
(() => calc())()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment