From 87d0b698a83ea58659e82a5f4fc0993f514c2eeb Mon Sep 17 00:00:00 2001 From: toni-santos Date: Thu, 17 Oct 2024 18:55:49 +0100 Subject: [PATCH] start getting information from schedule to the homepage --- content-scripts/index.js | 2 + content-scripts/modules/homepage-schedule.tsx | 89 +++++++++++++++++++ content-scripts/types.ts | 6 ++ 3 files changed, 97 insertions(+) create mode 100644 content-scripts/modules/homepage-schedule.tsx diff --git a/content-scripts/index.js b/content-scripts/index.js index d701920..9fbe601 100644 --- a/content-scripts/index.js +++ b/content-scripts/index.js @@ -18,6 +18,7 @@ import { fixPagination } from "./modules/pagination"; import { changeLayout } from "./modules/layout"; import { addStarIconToCard } from "./modules/favorite-course"; import { createComponentsPage } from "./pages/components_page"; +import { addMainPageSchedule } from "./modules/homepage-schedule"; /*-- - Docs: https://developer.chrome.com/docs/extensions/reference/storage/#synchronous-response-to-storage-updates @@ -51,6 +52,7 @@ const functionsToExecute = [ { name: "injectOverrideFunctions", func: injectOverrideFunctions }, { name: "addStarIconToCard", func: addStarIconToCard }, { name: "componentsPage", func: createComponentsPage }, + { name: "addMainPageSchedule", func: addMainPageSchedule }, ]; const init = async () => { diff --git a/content-scripts/modules/homepage-schedule.tsx b/content-scripts/modules/homepage-schedule.tsx new file mode 100644 index 0000000..4ac4195 --- /dev/null +++ b/content-scripts/modules/homepage-schedule.tsx @@ -0,0 +1,89 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import jsx from "texsaur"; +import { getUP } from "./utilities/sigarra"; +import { Lecture } from "../types"; + +// TODO: probably move this somewhere else +const getWeek: (date: Date) => number = function (date) { + const newYear = new Date(date.getFullYear(), 0, 1); + let day = newYear.getDay(); //the day of week the year begins on + day = day >= 0 ? day : day + 7; + const daynum = + Math.floor( + (date.getTime() - + newYear.getTime() - + (date.getTimezoneOffset() - newYear.getTimezoneOffset()) * + 60000) / + 86400000, + ) + 1; + let weeknum; + //if the year starts before the middle of a week + if (day < 4) { + weeknum = Math.floor((daynum + day - 1) / 7) + 1; + if (weeknum > 52) { + const nYear = new Date(date.getFullYear() + 1, 0, 1); + let nday = nYear.getDay(); + nday = nday >= 0 ? nday : nday + 7; + /*if the next year starts before the middle of + the week, it is week #1 of that year*/ + weeknum = nday < 4 ? 1 : 53; + } + } else { + weeknum = Math.floor((daynum + day - 1) / 7); + } + return weeknum; +}; + +const Schedule: (up: string) => Element = (up) => { + const current_year: number = new Date().getFullYear(); + + const schedule_url: (up: string) => string = (up: string) => + `https://sigarra.up.pt/feup/pt/hor_geral.estudantes_view?pv_num_unico=${up}&pv_ano_lectivo=${current_year}&pv_periodos=1`; + + return ( +