Infoeduka Plus

Dodaje potreban preostali broj dolazaka i minimalan postotak za potpis.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Infoeduka Plus
// @namespace    student.racunarstvo.hr
// @version      0.5
// @description  Dodaje potreban preostali broj dolazaka i minimalan postotak za potpis.
// @author       Kristijan Rosandić
// @match        *://student.racunarstvo.hr/*
// @match        *://student.algebra.hr/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function () {
  "use strict";

  let updated = false;
  setInterval(update, 100);

  function update() {
    const attendancesEl = document.querySelector("#attendances-stats");
    if (!attendancesEl) return (updated = false);
    const [statsA, statsB] = attendancesEl.children;
    setRemainingCount(statsA, 0.5);
    setRemainingCount(statsB, 0.6);
    updated = true;
  }

  function setRemainingCount(statsEl, perc) {
    const [presentCount, totalCount] = [
      ...statsEl.querySelectorAll("strong"),
    ].map((el) => parseInt(el.textContent));
    const listEl = statsEl.querySelector(".list-container");
    const arrivalsTotal = listEl.querySelectorAll("li").length;
    const hoursPerArrival = totalCount / arrivalsTotal;
    const requiredCount = Math.ceil(perc * totalCount);
    const requiredPerc = ((requiredCount / totalCount) * 100).toFixed(2);
    const remainingCount = Math.max(0, requiredCount - presentCount);
    const remainingArrivals =
      Math.round((remainingCount / hoursPerArrival) * 10) / 10;
    const text = `Još ${remainingArrivals}👤 za ${requiredPerc}%`;
    if (updated) listEl.firstElementChild.textContent = text;
    else {
      const div = document.createElement("div");
      listEl.prepend(div);
      div.setAttribute("style", "margin-top: 15px; text-align: center;");
      div.textContent = text;
    }
  }
})();