refactoring, using different pattern for page injection and reusing same pattern for both popup and content scripts

This commit is contained in:
Sriram Hariharan
2023-03-03 21:13:43 -06:00
parent 4ed52a3c9f
commit beb61176c1
18 changed files with 120 additions and 95 deletions

View File

@@ -0,0 +1,36 @@
/**
* An enum that represents the different types of pages that we support
* a given url/page can correspond to many of these enum values
*/
export enum SiteSupport {
COURSE_CATALOG = 'COURSE_CATALOG',
COURSE_CATALOG_LIST = 'COURSE_CATALOG_LIST',
COURSE_CATALOG_DETAILS = 'COURSE_CATALOG_DETAILS',
UT_PLANNER = 'UT_PLANNER',
WAITLIST = 'WAITLIST',
}
/**
* We use this function to determine what page the user is on, and then we can use that information to determine what to do
* @param url the url of the current page
* @returns a list of page types that the current page is
*/
export default function getSiteSupport(url: string): SiteSupport[] {
if (url.includes('utexas.collegescheduler.com')) {
return [SiteSupport.UT_PLANNER];
}
if (url.includes('utdirect.utexas.edu/apps/registrar/course_schedule')) {
const types = [SiteSupport.COURSE_CATALOG];
if (url.includes('results')) {
types.push(SiteSupport.COURSE_CATALOG_LIST);
}
if (document.querySelector('#details')) {
types.push(SiteSupport.COURSE_CATALOG_DETAILS);
}
return types;
}
if (url.includes('utdirect.utexas.edu') && (url.includes('waitlist') || url.includes('classlist'))) {
return [SiteSupport.WAITLIST];
}
return [];
}