Calculate Missed Hours for Classes

Automatically calculates the total hours missed for each class based on attendance records.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Calculate Missed Hours for Classes
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically calculates the total hours missed for each class based on attendance records.
// @match        https://stars.bilkent.edu.tr/srs/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function calculateMissedHours() {
        const attendanceDivs = document.querySelectorAll(".attendDiv");
        const results = [];

        attendanceDivs.forEach(attendDiv => {
            const className = attendDiv.querySelector("h4")?.innerText.trim() || "Unknown Class";
            const attendanceRows = attendDiv.querySelectorAll("table tr");
            let totalMissedHours = 0;

            attendanceRows.forEach((row, index) => {
                if (index === 0) return;
                const attendanceCell = row.cells[2];
                if (attendanceCell) {
                    const attended = parseInt(attendanceCell.querySelector("b")?.innerText || "0");
                    const total = parseInt(attendanceCell.innerText.split("/")[1].trim());
                    const missed = total - attended;
                    totalMissedHours += missed;
                }
            });

            results.push({ className, totalMissedHours });
        });

        if (results.length > 0) {
            results.forEach(result => {
                console.log(`Class: ${result.className}, Total Hours Missed: ${result.totalMissedHours}`);
                alert(`Class: ${result.className}, Total Hours Missed: ${result.totalMissedHours}`);
            });
        } else {
            console.log("No attendance data found.");
            alert("No attendance data found.");
        }
    }

    // Run the function automatically
    calculateMissedHours();
})();