Skip to content

Commit

Permalink
trying to get the CES stuff to work
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavchadaga committed Feb 22, 2024
1 parent 308e837 commit 1963543
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const HOST_PERMISSIONS: string[] = [
'*://*.catalog.utexas.edu/ribbit/',
'*://*.registrar.utexas.edu/schedules/*',
'*://*.login.utexas.edu/login/*',
'https://utexas.bluera.com/*',
];

const manifest = defineManifest(async () => ({
Expand Down
2 changes: 2 additions & 0 deletions src/pages/background/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MessageListener } from 'chrome-extension-toolkit';
import onInstall from './events/onInstall';
import onServiceWorkerAlive from './events/onServiceWorkerAlive';
import onUpdate from './events/onUpdate';
import CESHandler from './handler/CESHandler';
import browserActionHandler from './handler/browserActionHandler';
import tabManagementHandler from './handler/tabManagementHandler';
import userScheduleHandler from './handler/userScheduleHandler';
Expand Down Expand Up @@ -31,6 +32,7 @@ const messageListener = new MessageListener<BACKGROUND_MESSAGES>({
...browserActionHandler,
...tabManagementHandler,
...userScheduleHandler,
...CESHandler,
});

messageListener.listen();
53 changes: 53 additions & 0 deletions src/pages/background/handler/CESHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { MessageHandler } from 'chrome-extension-toolkit';
import { CESMessage } from 'src/shared/messages/CESMessage';

This comment has been minimized.

Copy link
@doprz

doprz Feb 22, 2024

Collaborator

import { CESMessage } from '@shared/messages/CESMessage';

import openNewTab from '../util/openNewTab';

const CESHandler: MessageHandler<CESMessage> = {
openCESPage({ data, sendResponse }) {
const { instructorFirstName, instructorLastName } = data;
console.log('openCESPage', instructorFirstName, instructorLastName);
const CESFall2023Url =
'https://utexas.bluera.com/utexas/rpvl.aspx?rid=d3db767b-049f-46c5-9a67-29c21c29c580&regl=en-US';

openNewTab(CESFall2023Url).then(sendResponse);
},
};

export default CESHandler;

// openNewTab(CESFall2023Url).then(tab => {
// const checkTabUpdatedAndComplete = (tabId: number, changeInfo: chrome.tabs.TabChangeInfo) => {
// if (tabId === tab.id && changeInfo.status === 'complete') {
// chrome.tabs.executeScript(
// tab.id,
// {
// code: `
// const inputElement = document.getElementById("ctl00_ContentPlaceHolder1_ViewList_tbxValue");
// if(inputElement) {
// inputElement.value = '${instructorFirstName} ${instructorLastName}';
// inputElement.focus();
// const enterKeyEvent = new KeyboardEvent('keydown', {key: 'Enter', code: 'Enter', keyCode: 13, which: 13, bubbles: true});
// inputElement.dispatchEvent(enterKeyEvent);
// }
// `,
// },
// () => {
// if (chrome.runtime.lastError) {
// console.error(chrome.runtime.lastError.message);
// sendResponse(null);
// } else {
// sendResponse(tab);
// }
// }
// );

// chrome.tabs.onUpdated.removeListener(checkTabUpdatedAndComplete);
// }
// };

// chrome.tabs.onUpdated.addListener(checkTabUpdatedAndComplete);
// });
// },
// };

// export default CESHandler;
10 changes: 8 additions & 2 deletions src/pages/content/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { createRoot } from 'react-dom/client';
import CourseCatalogMain from '@views/components/CourseCatalogMain';
import getSiteSupport, { SiteSupport } from '@views/lib/getSiteSupport';
import React from 'react';
import { createRoot } from 'react-dom/client';

const support = getSiteSupport(window.location.href);

Expand All @@ -16,3 +16,9 @@ if (support === SiteSupport.COURSE_CATALOG_DETAILS || support === SiteSupport.CO
</React.StrictMode>
);
}

if (support === SiteSupport.CES) {
alert('CES');
const input = document.getElementById('ctl00_ContentPlaceHolder1_ViewList_tbxValue') as HTMLInputElement;
console.log(input.value);
}
8 changes: 8 additions & 0 deletions src/shared/messages/CESMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface CESMessage {
/**
* Opens the CES page for the specified instructor
*
* @param data first and last name of the instructor
*/
openCESPage: (data: { instructorFirstName: string; instructorLastName: string }) => chrome.tabs.Tab;
}
3 changes: 2 additions & 1 deletion src/shared/messages/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { createMessenger } from 'chrome-extension-toolkit';
import BrowserActionMessages from './BrowserActionMessages';
import { CESMessage } from './CESMessage';
import TabManagementMessages from './TabManagementMessages';
import TAB_MESSAGES from './TabMessages';
import { UserScheduleMessages } from './UserScheduleMessages';

/**
* This is a type with all the message definitions that can be sent TO the background script
*/
export type BACKGROUND_MESSAGES = BrowserActionMessages & TabManagementMessages & UserScheduleMessages;
export type BACKGROUND_MESSAGES = BrowserActionMessages & TabManagementMessages & UserScheduleMessages & CESMessage;

/**
* A utility object that can be used to send type-safe messages to the background script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ interface DescriptionProps {
}

const Description: React.FC<DescriptionProps> = ({ lines }: DescriptionProps) => {
// TODO: This needs to fetch the url and grab the description from the course catalog
// IT WILL NOT ALREADY BE IN THE COURSE OBJECT (lookat CourseDescription.tsx for an example of how to do this)
const keywords = ['prerequisite', 'restricted'];
return (
<ul className='my-[5px] space-y-1.5 children:marker:text-ut-burntorange'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { Chip, flagMap } from '@views/components/common/Chip/Chip';
import Divider from '@views/components/common/Divider/Divider';
import Text from '@views/components/common/Text/Text';
import React, { useState } from 'react';
import addCourse from 'src/pages/background/lib/addCourse';
import removeCourse from 'src/pages/background/lib/removeCourse';
import { background } from 'src/shared/messages';

This comment has been minimized.

Copy link
@doprz

doprz Feb 22, 2024

Collaborator

Please use aliased imports here.

import { Course } from 'src/shared/types/Course';
import Instructor from 'src/shared/types/Instructor';
import { UserSchedule } from 'src/shared/types/UserSchedule';
import { openTabFromContentScript } from 'src/views/lib/openNewTabFromContentScript';
import Add from '~icons/material-symbols/add';
import CalendarMonth from '~icons/material-symbols/calendar-month';
import CloseIcon from '~icons/material-symbols/close';
Expand All @@ -18,6 +16,8 @@ import Mood from '~icons/material-symbols/mood';
import Remove from '~icons/material-symbols/remove';
import Reviews from '~icons/material-symbols/reviews';

const { openNewTab, addCourse, removeCourse, openCESPage } = background;

interface HeadingAndActionProps {
/* The course to display */
course: Course;
Expand All @@ -30,7 +30,7 @@ interface HeadingAndActionProps {
export const handleOpenCalendar = async () => {
// Not sure if it's bad practice to export this
const url = chrome.runtime.getURL('calendar.html');
await openTabFromContentScript(url);
openNewTab({ url });
};

/**
Expand All @@ -42,7 +42,7 @@ export const handleOpenCalendar = async () => {
const HeadingAndActions: React.FC<HeadingAndActionProps> = ({ course, onClose, activeSchedule }) => {
const { courseName, department, number: courseNumber, uniqueId, instructors, flags, schedule } = course;
const [courseAdded, setCourseAdded] = useState<boolean>(
activeSchedule?.courses.some(course => course.uniqueId === uniqueId)
activeSchedule !== undefined ? activeSchedule.courses.some(course => course.uniqueId === uniqueId) : false
);

const capitalizeString = (str: string) => str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
Expand All @@ -62,27 +62,33 @@ const HeadingAndActions: React.FC<HeadingAndActionProps> = ({ course, onClose, a
const instructorSearchTerm = getInstructorFullName(instructor);
instructorSearchTerm.replace(' ', '+');
const url = `https://www.ratemyprofessors.com/search/professors/1255?q=${instructorSearchTerm}`;
return openTabFromContentScript(url);
return openNewTab({ url });
});
await Promise.all(openTabs);
};
const handleOpenCES = async () => {
// TODO: does not look up the professor just takes you to the page
const cisUrl = 'https://utexas.bluera.com/utexas/rpvl.aspx?rid=d3db767b-049f-46c5-9a67-29c21c29c580&regl=en-US';
await openTabFromContentScript(cisUrl);
const openTabs = instructors.map(instructor => {
let { firstName, lastName } = instructor;
firstName = capitalizeString(firstName);
lastName = capitalizeString(lastName);
return openCESPage({ instructorFirstName: firstName, instructorLastName: lastName });
});
await Promise.all(openTabs);
};
const handleOpenPastSyllabi = async () => {
// not specific to professor
const url = `https://utdirect.utexas.edu/apps/student/coursedocs/nlogon/?year=&semester=&department=${department}&course_number=${courseNumber}&course_title=${courseName}&unique=&instructor_first=&instructor_last=&course_type=In+Residence&search=Search`;
await openTabFromContentScript(url);
openNewTab({ url });
};
const handleAddOrRemoveCourse = async () => {
if (!activeSchedule) return;
if (!courseAdded) {
await addCourse(activeSchedule.name, course);
addCourse({ course, scheduleName: activeSchedule.name });
} else {
await removeCourse(activeSchedule.name, course);
removeCourse({ course, scheduleName: activeSchedule.name });
}
setCourseAdded(!courseAdded);
setCourseAdded(prev => !prev);
};
return (
<div className='w-full pb-3 pt-6'>
Expand Down
4 changes: 4 additions & 0 deletions src/views/lib/getSiteSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum SiteSupport {
WAITLIST = 'WAITLIST',
EXTENSION_POPUP = 'EXTENSION_POPUP',
MY_CALENDAR = 'MY_CALENDAR',
CES = 'CES',
}

/**
Expand Down Expand Up @@ -39,5 +40,8 @@ export default function getSiteSupport(url: string): SiteSupport | null {
if (url.includes('utdirect.utexas.edu') && (url.includes('waitlist') || url.includes('classlist'))) {
return SiteSupport.WAITLIST;
}
if (url.includes('utexas.bluera')) {
return SiteSupport.CES;
}
return null;
}

0 comments on commit 1963543

Please sign in to comment.