Calculate Missed Hours for Classes

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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();
})();