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

Clean up fetch options #13

Merged
merged 1 commit into from
Sep 19, 2023
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
20 changes: 1 addition & 19 deletions content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,27 +214,9 @@ function calculateProgressBarAndDisplay() {
if (parseSubjectsResult.idOptativas) {
// Setup the fetch
const optativasUrl = `${baseUrl}/plan_estudio/optativas`;
const options = {
headers: {
accept: "application/json, text/javascript, */*; q=0.01",
"accept-language":
"es-AR,es;q=0.9,es-419;q=0.8,en;q=0.7,pt;q=0.6,gl;q=0.5,ru;q=0.4",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"sec-ch-ua":
'"Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-requested-with": "XMLHttpRequest",
},
body: `elemento=${parseSubjectsResult.idOptativas}`,
method: "POST",
};

// Perform the fetch operation for optional subjects
fetch(optativasUrl, options)
fetch(optativasUrl, getOptativasOptions(idOptativas))
.then((response) =>
response.json().then((data) => {
optionalsPassedExamsCount = parseOptionalSubjects(data.cont);
Expand Down
44 changes: 35 additions & 9 deletions content/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,39 @@ function getStudentDegree(document) {
*
* @returns {string[]} An array of degree names.
*/
function getUNLPInfoDegrees(){
return [
"Licenciatura en Sistemas",
"Licenciatura en Informática",
"Ingeniería en Computación",
"Analista Programador Universitario",
"Analista en Tecnologías de la Información y la Comunicación",
"ATIC",
];
function getUNLPInfoDegrees() {
return [
"Licenciatura en Sistemas",
"Licenciatura en Informática",
"Ingeniería en Computación",
"Analista Programador Universitario",
"Analista en Tecnologías de la Información y la Comunicación",
"ATIC",
];
}

/**
* Constructs and returns options for making a POST request to retrieve optional subjects.
*
* @param {string} idOptativas - The ID of the optativas element to retrieve.
* @returns {Object} - An object containing the HTTP request options.
*/
function getOptativasOptions(idOptativas) {
// Define the headers for the request
const headers = {
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
};

// Create the request body with the provided idOptativas
const body = `elemento=${idOptativas}`;

// Define the HTTP method as POST
const method = "POST";

// Construct and return the options object
return {
headers,
body,
method,
};
}