Kepler Not Script

Kepler için notlar

当前为 2025-01-04 提交的版本,查看 最新版本

// ==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://gf.qytechs.cn/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();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址