Kepler Not Script

Kepler için notlar

目前為 2025-01-04 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Kepler Not Script
// @author       KazuroAkashi
// @match        https://obs.itu.edu.tr/ogrenci/
// @description  Kepler için notlar
// @license MIT
// @version 0.0.1.20250104132430
// @namespace https://greasyfork.org/users/1419483
// ==/UserScript==

(function() {
    'use strict';

    async function getJWT() {
        return new Promise((resolve, reject) => {
            const xhr = new XMLHttpRequest();
            xhr.open("GET", "https://obs.itu.edu.tr/ogrenci/auth/jwt");

            xhr.onload = () => {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    resolve(xhr.responseText);
                } else {
                    reject(xhr.status);
                }
            };
            xhr.send();
        })
    }

    async function getDonemListesi(jwt) {
        return new Promise((resolve, reject) => {
            const xhr = new XMLHttpRequest();
            xhr.open("GET", "https://obs.itu.edu.tr/api/ogrenci/DonemListesi");
            xhr.setRequestHeader("Authorization", "Bearer " + jwt);

            xhr.onload = () => {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    resolve(JSON.parse(xhr.response));
                } else {
                    reject(xhr.status);
                }
            };
            xhr.send();
        })
    }

    async function getSinifListesi(jwt, donemId) {
        return new Promise((resolve, reject) => {
            const xhr = new XMLHttpRequest();
            xhr.open("GET", "https://obs.itu.edu.tr/api/ogrenci/sinif/KayitliSinifListesi/" + donemId);
            xhr.setRequestHeader("Authorization", "Bearer " + jwt);

            xhr.onload = () => {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    resolve(JSON.parse(xhr.response));
                } else {
                    reject(xhr.status);
                }
            };
            xhr.send();
        })
    }

    async function getNotListesi(jwt, sinifId) {
        return new Promise((resolve, reject) => {
            const xhr = new XMLHttpRequest();
            xhr.open("GET", "https://obs.itu.edu.tr/api/ogrenci/Sinif/SinifDonemIciNotListesi/" + sinifId);
            xhr.setRequestHeader("Authorization", "Bearer " + jwt);

            xhr.onload = () => {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    resolve(JSON.parse(xhr.response));
                } else {
                    reject(xhr.status);
                }
            };
            xhr.send();
        })
    }

    async function printNotlar() {
        const jwt = await getJWT();
        const donemListesi = (await getDonemListesi(jwt)).ogrenciDonemListesi;
        const sonDonem = donemListesi[donemListesi.length - 1];
        const sonDonemId = sonDonem.akademikDonemId;
        const sinifListesi = (await getSinifListesi(jwt, sonDonemId)).kayitSinifResultList;

        const addBefore = document.querySelectorAll(".obs > .container-fluid > div > .row")[1]

        const parentRow = document.createElement("div");
        parentRow.className = "row";
        addBefore.parentElement.insertBefore(parentRow, addBefore);

        const colInParentRow = document.createElement("div");
        colInParentRow.className = "col-md-12 mb-5";
        parentRow.appendChild(colInParentRow);

        const cardInCol = document.createElement("div");
        cardInCol.className = "card info-graphic info-graphic--service";
        colInParentRow.appendChild(cardInCol);

        const bodyInCard = document.createElement("div");
        bodyInCard.className = "card-body";
        cardInCol.appendChild(bodyInCard);

        const title = document.createElement("h2");
        title.innerText = "Notlar";
        bodyInCard.appendChild(title);

        for (const sinif of sinifListesi) {
            const sinifNameEn = sinif.bransKodu + sinif.dersKodu + " - " + sinif.dersAdiEN + " (CRN: " + sinif.crn + ")";
            const sinifNameTr = sinif.bransKodu + sinif.dersKodu + " - " + sinif.dersAdiTR + " (CRN: " + sinif.crn + ")";
            const sinifId = sinif.sinifId;

            const notListesiObj = (await getNotListesi(jwt, sinifId));
            const notListesi = notListesiObj.sinifDonemIciNotListesi;
            const ortalama = notListesiObj.ortalama;

            const sinifCard = document.createElement("div");
            sinifCard.className = "col-lg-12 mb-3";
            bodyInCard.appendChild(sinifCard);

            const sinifNameEl = document.createElement("h4");
            sinifNameEl.innerText = sinifNameTr;
            sinifCard.appendChild(sinifNameEl);

            for (const not of notListesi) {
                const notName = not.degerlendirmeOlcutuAdi;
                const notPerc = not.degerlendirmeKatkisi;
                const notValue = not.not;

                const sinifNot = document.createElement("div");
                sinifNot.className = "row ml-5";
                sinifCard.appendChild(sinifNot);

                const notNameEl = document.createElement("h5");
                notNameEl.innerText = notName + " (%" + notPerc + ")";
                sinifNot.appendChild(notNameEl);

                const notValEl = document.createElement("div");
                notValEl.className = "ml-5";
                notValEl.innerText = notValue;
                sinifNot.appendChild(notValEl);
            }
            const sinifNot = document.createElement("div");
            sinifNot.className = "row ml-5";
            sinifCard.appendChild(sinifNot);

            const notNameEl = document.createElement("h5");
            notNameEl.innerText = "Ağırlıklı Ortalama";
            sinifNot.appendChild(notNameEl);

            const notValEl = document.createElement("div");
            notValEl.className = "ml-5";
            notValEl.innerText = ortalama;
            sinifNot.appendChild(notValEl);
        }
    }

    printNotlar();
})();