Schoolbook Tools

Mess around with schoolbook.ge

目前為 2023-05-09 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Schoolbook Tools
// @namespace   https://github.com/naviamold1
// @match       https://eservices.schoolbook.ge/*
// @homepage    https://greasyfork.org/en/scripts/459858-schoolbook-tools
// @grant       GM_getValue
// @version     1.5
// @author      Naviamold
// @description Mess around with schoolbook.ge
// @license MIT
// ==/UserScript==

(function () {
  "use strict";

  // do not change anything here if you dont know what you are doing!

  function newGrade(grade) {
    let grades = document.querySelectorAll(".avg_value");
    let totalGrade = document.querySelectorAll("#saertosashualo span");
    const final = [...grades, ...totalGrade];
    final.forEach((val) => (val.innerHTML = grade));
  }

  function newAttendance(attendance) {
    let attendances = document.querySelectorAll(".prc");
    let totalAttendance = document.querySelectorAll(".sec span");
    const final = [...attendances, ...totalAttendance];
    final.forEach((val) => (val.innerHTML = attendance));
  }

  function removeComments() {
    let comment = document.querySelectorAll(".notificationsList");
    let comment1 = document.querySelectorAll(".notificationsListalter");
    let messages = document.querySelectorAll(".homeworkContent");
    const final = [...comment, ...comment1, ...messages];
    final.forEach((mes) => (mes.style.display = "none"));
  }

  function liveUpdate() {
    let totalGrade = document.querySelector("#saertosashualo span");
    totalGrade.click();
    setTimeout(() => {
      closeGradeDialog();
      let numbers = [];
      document
        .querySelectorAll(
          "#cnt > div.div_container_grades > table > tbody > tr > td:nth-child(4)"
        )
        .forEach((el) => {
          let text = el.innerText || el.textContent;
          let number = parseInt(text.replace(/\D/g, ""));
          if (!isNaN(number)) {
            numbers.push(number);
          }
        });

      let sum = numbers.reduce((acc, val) => acc + val, 0);

      let avg = 0;
      if (numbers.length > 0) {
        avg = sum / numbers.length;
      }

      avg = Math.round(avg * 100) / 100;

      totalGrade.innerHTML = avg;
    }, 1000);
  }

  function gradeSpier() {
    $("body").append(`
    <form id="gmSomeID">
    <input placeholder="Grade Viewer - ID" id="gminput">
    <button id="gmview">View</button>
    </form>
    `);
    const getter = (e) => {
      e.preventDefault();
      let val = document.querySelector("#gminput").value;
      gradeclick(val, -1);
    };
    $("#gmview").click(getter);
  }

  function attendanceSpier() {
    $("body").append(`
    <form id="gmSomeID2">
    <input placeholder="Attendance Viewer - ID" id="gminput2">
    <input placeholder="Subject ID" id="gminput3">
    <button id="gmview2">View</button>
    </form>
    `);
    const getter = (e) => {
      e.preventDefault();
      let val = document.querySelector("#gminput2").value;
      let val2 = document.querySelector("#gminput3").value;
      attendanceclick(val, val2);
    };
    $("#gmview2").click(getter);
  }

  if (
    window.location.href === "https://eservices.schoolbook.ge/Parent/Index" ||
    window.location.href ===
      "https://eservices.schoolbook.ge/Parent/AllSubjects"
  ) {
    if (GM_getValue("changeGrade")) {
      setTimeout(() => {
        newGrade(GM_getValue("changeGrade"));
      }, 100);
    }
    if (GM_getValue("changeAttendance")) {
      setTimeout(() => {
        newAttendance(GM_getValue("changeAttendance"));
      }, 100);
    }

    if (GM_getValue("liveGradeUpdate")) {
      liveUpdate();
    }

    if (GM_getValue("gradeViewer")) {
      gradeSpier();
    }

    if (GM_getValue("attendanceViewer")) {
      attendanceSpier();
    }
  }

  if (
    window.location.href === "https://eservices.schoolbook.ge/Parent/Messages"
  ) {
    if (GM_getValue("hideComments")) {
      removeComments();
    }
  }
})();