Infoeduka Plus

Dodaje potreban preostali broj dolazaka i minimalan postotak za potpis.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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;
    }
  }
})();