Skip to content

Commit

Permalink
refac: better usability
Browse files Browse the repository at this point in the history
  • Loading branch information
Joabesv committed May 24, 2024
1 parent f09aa4d commit c1ffc36
Showing 1 changed file with 30 additions and 47 deletions.
77 changes: 30 additions & 47 deletions src/scripts/contentScriptSigaa.js
Original file line number Diff line number Diff line change
@@ -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: `
<div class='toast-loading-text' style='width: 250px'>
<img src=${logoWhite} width="120" style="margin-bottom: 8px" />
<p style="padding-bottom: 8px;">Atualizando suas informações...</p>\n\n
<b>Olá ${name.email}</b>
<b>NÃO SAIA DESSA PÁGINA,</b>
<p>apenas aguarde, no máx. 5 min 🙏</p>
</div>`,
duration: -1,
Expand All @@ -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: `
<div class='toast-loading-text' style='width: 250px'>
<img src=${logoWhite} width="120" style="margin-bottom: 8px" />
<p style="padding-bottom: 8px;">${student.name.split(' ')[0]} Acesse suas notas!</p>\n\n
<b>Clique no menu Ensino > consultar minhas notas</b>
</div>`,
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(
Expand Down

0 comments on commit c1ffc36

Please sign in to comment.