Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: first draft to new integration #74

Merged
merged 20 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/scripts/contentScriptSigaa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { scrapeGradesConsulting, scrapeHomepage } from "../utils/sigaa";
import { NextAPI } from "../services/NextAPI";
import {
errorToast,
redirectToast,
processingToast,
} from "../utils/nextToasts";

const nextApi = NextAPI();

const sigaaURL = new URL(document.location.href);
const isDiscentesPath = sigaaURL.pathname.includes("discente.jsf");

if (
isDiscentesPath &&
document.contains(document.querySelector("#agenda-docente"))
) {
const student = scrapeHomepage();
const toast = redirectToast(student.name);
localStorage.setItem("studentInfo", JSON.stringify(student));
toast.showToast();
}

if (isDiscentesPath && document.contains(document.querySelector(".notas"))) {
processingToast.showToast();
const studentHistory = scrapeGradesConsulting();
// todo: fazer o endpoint
const { data: res } = nextApi
.post("/histories/sigaa", studentHistory, {
timeout: 60 * 1 * 1000, // 1 minute
})
.catch((err) => {
processingToast.hideToast();
console.log(err);
errorToast.showToast();
});

console.log(res);
}
152 changes: 77 additions & 75 deletions src/scripts/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,89 +17,91 @@ import Utils from "../utils/extensionUtils";
// CSS imports
import "element-ui/lib/theme-chalk/index.css";

let matricula_url;
let matriculasURL;

if (process.env.NODE_ENV == "production") {
matricula_url = [
"matricula.ufabc.edu.br/matricula",
"ufabc-matricula.cdd.naoseiprogramar.com.br/snapshot",
"api.ufabcnext.com/snapshot",
];
matriculasURL = [
"matricula.ufabc.edu.br/matricula",
"ufabc-matricula.cdd.naoseiprogramar.com.br/snapshot",
"api.ufabcnext.com/snapshot",
];
} else {
matricula_url = [
"matricula.ufabc.edu.br/matricula",
"api.ufabcnext.com/snapshot",
"api.ufabcnext.com/snapshot/backup.html",
"ufabc-matricula.cdd.naoseiprogramar.com.br/snapshot",
"ufabc-matricula.cdd.naoseiprogramar.com.br/snapshot/backup.html",
"ufabc-matricula-test.cdd.naoseiprogramar.com.br/snapshot",
"ufabc-matricula-test.cdd.naoseiprogramar.com.br/snapshot/backup.html",
"locahost:8011/snapshot",
"locahost:8011/snapshot/backup.html",
];
matriculasURL = [
"matricula.ufabc.edu.br/matricula",
"api.ufabcnext.com/snapshot",
"api.ufabcnext.com/snapshot/backup.html",
"locahost:8011/snapshot",
"locahost:8011/snapshot/backup.html",
"https://sig.ufabc.edu.br/sigaa/portais/discente/discente.jsf",
];
}

if (!isBrowser) {
console.log("Not running on browser!");
load();
console.log("Not running on browser!");
load();
} else {
window.addEventListener("load", load);
window.addEventListener("load", load);
}

async function load() {
const currentUrl = document.location.href;
// add cross-domain local storage
Utils.injectScript("lib/xdLocalStorage.min.js");
Utils.injectIframe("pages/iframe.html");
Utils.injectScript("lib/init.js");

setupStorage();
require("./contentScriptPortal");

if (matricula_url.some((url) => currentUrl.indexOf(url) != -1)) {
// update teachers locally
setTimeout(async () => {
let lastUpdate = null;
try {
lastUpdate = await Utils.storage.getItem("ufabc-extension-last");
} catch (err) {
lastUpdate = Date.now();
} finally {
matriculaUtils.updateProfessors(lastUpdate);
}

// this is the main vue app
// i.e, where all the filters live
const anchor = document.createElement("div");
anchor.setAttribute("id", "app");
$("#meio").prepend(anchor);

//inject styles
Utils.injectStyle("styles/main.css");

// manda as informacoes para o servidor
matriculaUtils.sendAlunoData();

// load vue app modal
const modal = document.createElement("div");
modal.setAttribute("id", "modal");
modal.setAttribute("data-app", true);
document.body.append(modal);

// load vue app teacherReview
const teacherReview = document.createElement("div");
teacherReview.setAttribute("id", "teacherReview");
teacherReview.setAttribute("data-app", true);
document.body.append(teacherReview);

// load vue app review subjects
const reviewSubject = document.createElement("div");
reviewSubject.setAttribute("id", "review-subject");
reviewSubject.setAttribute("data-app", true);
document.body.append(reviewSubject);

// inject Vue app
Utils.injectScript("scripts/main.js");
}, 1500);
}
const currentURL = new URL(document.location);
// add cross-domain local storage
Utils.injectScript("lib/xdLocalStorage.min.js");
Utils.injectIframe("pages/iframe.html");
Utils.injectScript("lib/init.js");

setupStorage();
require("./contentScriptSigaa");

const shouldInject = matriculasURL.some((url) =>
currentURL.href.includes(url),
);

if (!shouldInject) {
return;
}
// update teachers locally
setTimeout(async () => {
let lastUpdate = null;
try {
lastUpdate = await Utils.storage.getItem("ufabc-extension-last");
} catch (err) {
lastUpdate = Date.now();
} finally {
matriculaUtils.updateProfessors(lastUpdate);
}

// this is the main vue app
// i.e, where all the filters live
const anchor = document.createElement("div"); // filtros da tela de matriculas
anchor.setAttribute("id", "app");
$("#meio").prepend(anchor);

//inject styles
Utils.injectStyle("styles/main.css");

// manda as informacoes para o servidor
matriculaUtils.sendAlunoData();

// load vue app modal
const modal = document.createElement("div");
modal.setAttribute("id", "modal");
modal.setAttribute("data-app", true);
document.body.append(modal);

// load vue app teacherReview
const teacherReview = document.createElement("div");
teacherReview.setAttribute("id", "teacherReview");
teacherReview.setAttribute("data-app", true);
document.body.append(teacherReview);

// load vue app review subjects
const reviewSubject = document.createElement("div");
reviewSubject.setAttribute("id", "review-subject");
reviewSubject.setAttribute("data-app", true);
document.body.append(reviewSubject);

// inject Vue app
Utils.injectScript("scripts/main.js");
}, 1500);
}
4 changes: 2 additions & 2 deletions src/services/NextAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import Axios from "axios";
function resolveEndpoint(env) {
return (
{
development: "http://localhost:8011/v1",
development: "http://localhost:5000/v2",
staging: "https://ufabc-matricula-test.cdd.naoseiprogramar.com.br/v1",
production: "https://api.ufabcnext.com/v1",
}[env] || "http://localhost:8011/v1"
}[env] || "http://localhost:5000/v2"
);
}

Expand Down
69 changes: 69 additions & 0 deletions src/utils/nextToasts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import Toastify from "toastify-js";
import "toastify-js/src/toastify.css";
import Utils from "../utils/extensionUtils";
const loading = require("../images/loading.svg");
const logoWhite = require("../images/logo-white.svg");
const errorSVG = require("../images/error.svg");

Utils.injectStyle("styles/portal.css");

const errorToast = Toastify({
text: `
<div style="width: 228px; display: flex; align-items: end; margin-right: 12px;">
<img style="margin-right: 16px;" width="32" height="32" src="${errorSVG}" />
Não foi possível salvar seus dados, recarregue a página e aguarde.
</div>`,
duration: -1,
close: true,
gravity: "top",
position: "right",
className: "toast-error-container",
escapeMarkup: false,
style: {
background: "#E74C3C;",
},
});

const redirectToast = (studentname) =>
Toastify({
text: `
<div class='toast-loading-text' style='width: 250px'>
<img src=${logoWhite} width="120" style="margin-bottom: 8px" />
<p style="padding-bottom: 8px;">${studentname} 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,
});

const processingToast = 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>NÃO SAIA DESSA PÁGINA,</b>
<p>apenas aguarde, no máx. 5 min 🙏</p>
</div>`,
duration: -1,
close: false,
gravity: "bottom",
position: "right",
className: "toast-loading",
escapeMarkup: false,
avatar: loading,
style: {
background: "linear-gradient(to right, #2E7EED, rgba(46, 126, 237, 0.5));",
},
});

module.exports = {
errorToast,
redirectToast,
processingToast,
};
Loading