Skip to content

Commit

Permalink
feat: kronk.gif
Browse files Browse the repository at this point in the history
  • Loading branch information
DereC4 committed Nov 20, 2024
1 parent c2d4d72 commit 02cbb1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
6 changes: 1 addition & 5 deletions src/pages/background/lib/addCourseByURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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!;
Expand Down
18 changes: 12 additions & 6 deletions src/views/components/injected/AddAllButton.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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.');
}
};

Expand Down

0 comments on commit 02cbb1a

Please sign in to comment.