average vulcan

calculate average grades in vulcan

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         average vulcan
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  calculate average grades in vulcan
// @author       bewu
// @license      MIT
// @match        https://uonetplus-uczen.vulcan.net.pl/*
// @icon         https://cdn-icons-png.flaticon.com/512/5084/5084428.png
// @grant        none
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';
    console.info("average vulcan by bewu");

    var subjectsDiv = $("#ext-element-110");
    var waitGrades = setInterval(function() {
        if (subjectsDiv.length != 0 && subjectsDiv[0].childElementCount != 0) {
            console.info("loaded grades!");
            clearInterval(waitGrades);

            start(subjectsDiv[0]);
        }
        else {
            subjectsDiv = $("#ext-element-110");
        }
    }, 100);
})();

function start(subjects) {
    console.info(subjects);
    for (var i = 0; i < subjects.childElementCount; i++) {
        avg(subjects.children[i], subjects.getElementsByClassName("x-label-el")[i]);
    }
}

function avg(s, sName) {
    s = s.querySelectorAll("span[aria-label]");

    if (s.length != 0) { // if there are any grades
        console.info(sName.innerText);
        var gSum = 0.0;
        var weightSum = 0;

        for (var i = 0; i < s.length; i++) {
            var tempG = s[i].innerText.replace(" (%)", "") // temp string to hold grade
            if (tempG.length > 1) { // if grade is not only + or -
                tempG = tempG.replace("+", ".5");

                if (tempG.includes("-")) { // handling grades with a -
                    tempG = tempG.replace("-", ".0");
                    if (!isNaN(tempG)) {
                        tempG = (parseInt(tempG) - 0.25).toString();
                    }
                }
            }

            if (!isNaN(tempG)) { // if the grade is numeric
                var tempW = s[i].getAttribute("aria-label").split("waga: ")[1].split(",")[0]; // temp string to hold grade's weight

                if (tempW != "0") { // if weight is not 0
                    gSum += parseInt(tempW) * parseFloat(tempG);
                    weightSum += parseInt(tempW);

                    console.info(tempG + " " + tempW);
                }
            }
        }

        var sAverage;
        if (weightSum > 0) { // to avoid dividing by 0
            sAverage = Math.round(gSum / weightSum * 100) / 100; // calculating the average

            console.info(sName.innerText + " " + sAverage);
            sName.innerHTML = sName.innerText + "<i> (" + sAverage + ")</i>";
        }
    }
}