diff --git a/src/pages/background/lib/addCourseByURL.ts b/src/pages/background/lib/addCourseByURL.ts index ec0395b1..2d3f7d6b 100644 --- a/src/pages/background/lib/addCourseByURL.ts +++ b/src/pages/background/lib/addCourseByURL.ts @@ -24,8 +24,7 @@ export async function addCourseByURL(activeSchedule: UserSchedule, link?: string // Exit if the user cancels the prompt if (!link) return; - console.log('DEREK THREE'); - console.log(link); + try { let htmlText: string; try { @@ -39,17 +38,14 @@ export async function addCourseByURL(activeSchedule: UserSchedule, link?: string alert(`Failed to fetch url '${link}'`); return; } - console.log(htmlText); const doc = new DOMParser().parseFromString(htmlText, 'text/html'); const scraper = new CourseCatalogScraper(SiteSupport.COURSE_CATALOG_DETAILS, doc, link); const tableRows = getCourseTableRows(doc); const scrapedCourses = scraper.scrape(tableRows, false); - console.log('DEREK FOUR'); if (scrapedCourses.length !== 1) return; - console.log('DEREK FIVE'); const description = scraper.getDescription(doc); const row = scrapedCourses[0]!; const course = row.course!; diff --git a/src/views/components/injected/AddAllButton.tsx b/src/views/components/injected/AddAllButton.tsx index e46db451..bbf20cfa 100644 --- a/src/views/components/injected/AddAllButton.tsx +++ b/src/views/components/injected/AddAllButton.tsx @@ -1,4 +1,5 @@ import { addCourseByURL } from '@pages/background/lib/addCourseByURL'; +import { background } from '@shared/messages'; import { validateLoginStatus } from '@shared/util/checkLoginStatus'; import { Button } from '@views/components/common/Button'; import ExtensionRoot from '@views/components/common/ExtensionRoot/ExtensionRoot'; @@ -31,13 +32,18 @@ export default function InjectedButton(): JSX.Element | null { // Make sure to remove duplicate anchorTags using set const uniqueAnchorTags = Array.from(new Set(anchorTags.map(a => a.href))); - if (uniqueAnchorTags[0]) { - await validateLoginStatus(uniqueAnchorTags[0]); - } + // Make sure user is logged in + const loggedInToUT = await background.validateLoginStatus({ + url: 'https://utdirect.utexas.edu/apps/registrar/course_schedule/utrp_login/', + }); - for (const a of uniqueAnchorTags) { - // eslint-disable-next-line no-await-in-loop - await addCourseByURL(activeSchedule, a); + if (loggedInToUT) { + for (const a of uniqueAnchorTags) { + // eslint-disable-next-line no-await-in-loop + await addCourseByURL(activeSchedule, a); + } + } else { + window.alert('Logged into UT Registrar.'); } };