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 (
+
+ );
+};
+
+export const addMainPageSchedule = async () => {
+ const up = getUP();
+ const schedule = Schedule(up);
+ document.body.appendChild(schedule);
+
+ const scheduleIframe = document.getElementById(
+ "main-page-schedule",
+ ) as HTMLIFrameElement;
+
+ const json = await new Promise((resolve) => {
+ scheduleIframe.onload = resolve;
+ return;
+ }).then(async () => {
+ const api_url = scheduleIframe?.contentWindow?.document
+ .getElementById("cal-shadow-container")
+ ?.getAttribute("data-evt-source-url");
+
+ const res = await fetch(api_url as string);
+ return res.json();
+ });
+
+ const weeks_map: Map> = new Map();
+ json.data.forEach((lecture: Lecture) => {
+ const start = getWeek(new Date(lecture.start));
+ if (weeks_map.has(start)) {
+ weeks_map.get(start)?.push(lecture);
+ } else {
+ weeks_map.set(start, [lecture]);
+ }
+ });
+
+ // TODO: create the actual schedule element
+ console.log(weeks_map);
+};
diff --git a/content-scripts/types.ts b/content-scripts/types.ts
index 7d22d29..441e25e 100644
--- a/content-scripts/types.ts
+++ b/content-scripts/types.ts
@@ -3,3 +3,9 @@ export type AuthSession = {
name: string;
hasNotifications: boolean;
};
+
+// TODO: Add more types as needed
+export type Lecture = {
+ ucs: Array