From c1ffc3695e3d92828d192da97879b568dde44230 Mon Sep 17 00:00:00 2001 From: Joabesv Date: Fri, 24 May 2024 11:17:46 -0300 Subject: [PATCH] refac: better usability --- src/scripts/contentScriptSigaa.js | 77 ++++++++++++------------------- 1 file changed, 30 insertions(+), 47 deletions(-) diff --git a/src/scripts/contentScriptSigaa.js b/src/scripts/contentScriptSigaa.js index f441826..8a394ea 100644 --- a/src/scripts/contentScriptSigaa.js +++ b/src/scripts/contentScriptSigaa.js @@ -1,33 +1,22 @@ import Toastify from "toastify-js"; import "toastify-js/src/toastify.css"; import Utils from "../utils/extensionUtils"; -import { normalizeDiacritics, scrapeGradesConsulting } from "../utils/sigaa"; +import { scrapeGradesConsulting, scrapeHomepage } from "../utils/sigaa"; Utils.injectStyle("styles/portal.css"); const loading = require("../images/loading.svg"); -const errorSVG = require("../images/error.svg"); const logoWhite = require("../images/logo-white.svg"); -const trs = document.querySelectorAll("#agenda-docente tbody tr"); -const tablesRowsArray = Array.from(trs); -const rawStudentInfo = tablesRowsArray.map((line) => - Array.from(line.children).map((column) => - normalizeDiacritics(column.innerText), - ), -); -const studentInfo = Object.fromEntries(rawStudentInfo); const sigaaURL = new URL(document.location.href); const isDiscentesPath = sigaaURL.pathname.includes("discente.jsf"); -const toast = () => { - const name = JSON.parse(localStorage.getItem("studentInfo")); - console.log(name) - return new Toastify({ +const toast = Toastify({ text: `
+

Atualizando suas informações...

\n\n - Olá ${name.email} + NÃO SAIA DESSA PÁGINA,

apenas aguarde, no máx. 5 min 🙏

`, duration: -1, @@ -41,41 +30,35 @@ const toast = () => { background: "linear-gradient(to right, #2E7EED, rgba(46, 126, 237, 0.5));", }, - }); -}; +}); -if (isDiscentesPath) { - const observer = new MutationObserver((list) => { - if (document.contains(document.querySelector(".notas"))) { - console.log("local", localStorage.getItem("studentHistory")); - const result = scrapeGradesConsulting(); - localStorage.setItem("studentHistory", JSON.stringify(result)); - console.log("It's in the DOM! 0"); - toast().showToast(); - observer.disconnect(); - } - }); - - const newObserver = new MutationObserver((list) => { - if (document.contains(document.querySelector("#agenda-docente"))) { - localStorage.setItem("userInfo", JSON.stringify(studentInfo)); - console.log("It's in the DOM! 1"); - toast().showToast(); - newObserver.disconnect(); - } - }); +if (isDiscentesPath && document.contains(document.querySelector("#agenda-docente"))) { + Utils.injectStyle("styles/portal.css"); + const student = scrapeHomepage(); + localStorage.setItem("studentInfo", JSON.stringify(student)); + Toastify({ + text: ` +
+ +

${student.name.split(' ')[0]} Acesse suas notas!

\n\n + Clique no menu Ensino > consultar minhas notas +
`, + gravity: "bottom", + position: "right", + duration: 5000, + style: { + background: + "linear-gradient(to right, #2E7EED, rgba(46, 126, 237, 0.5));", + }, + escapeMarkup: false, + }).showToast() +} - newObserver.observe(document.body, { - attributes: true, - childList: true, - subtree: true, - }); - observer.observe(document.body, { - attributes: true, - childList: true, - subtree: true, - }); +if(isDiscentesPath && document.contains(document.querySelector('.notas'))) { + const student = JSON.parse(localStorage.getItem("studentInfo")); + const result = scrapeGradesConsulting(); + toast.showToast(); } // await nextApi.post(