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,2 @@

View File

@@ -0,0 +1,20 @@
/**
* The course schedule page has a search form that allows users to search for courses by department and course level.
* The problem is that once the user triggers a search and refreshes the page,
* for some reason the search form is cleared and the user has to re-enter their search parameters. This fixes that lol
*/
export function populateSearchInputs() {
let params = new URL(window.location.href).searchParams;
let department = params.get('fos_fl');
let courseLevel = params.get('level');
if (!department || !courseLevel) return;
const depInput = document.querySelector<HTMLInputElement>('#fos_fl');
const levelInput = document.querySelector<HTMLInputElement>('#level');
if (!depInput || !levelInput) return;
depInput.value = department;
levelInput.value = courseLevel;
}

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 [];
}