textbook button, properly scraping the semester (year and season) from the url"

This commit is contained in:
Sriram Hariharan
2023-03-07 22:17:17 -06:00
parent 353c43c987
commit f3bf746c6e
4 changed files with 55 additions and 22 deletions

View File

@@ -25,7 +25,9 @@ export type Semester = {
/** The year that the semester is in */
year: number;
/** The season that the semester is in (Fall, Spring, Summer) */
season: string;
season: 'Fall' | 'Spring' | 'Summer';
/** UT's code for the semester */
code: string;
};
/**

View File

@@ -53,6 +53,14 @@ export default function CourseButtons({ course }: Props) {
openNewTab({ url: url.toString() });
};
const openTextbookURL = () => {
const { department, number, semester, uniqueId } = course;
const url = new URL('https://www.universitycoop.com/adoption-search-results');
url.searchParams.append('sn', `${semester.code}__${department}__${number}__${uniqueId}`);
openNewTab({ url: url.toString() });
};
return (
<Card className={styles.container}>
<Button
@@ -72,7 +80,7 @@ export default function CourseButtons({ course }: Props) {
</Text>
<Icon className={styles.icon} color='white' name='grading' size='medium' />
</Button>
<Button type='tertiary' className={styles.button}>
<Button onClick={openTextbookURL} type='tertiary' className={styles.button}>
<Text size='medium' weight='regular' color='white'>
Textbook
</Text>

View File

@@ -1,5 +1,5 @@
import { Serialized } from 'chrome-extension-toolkit';
import { Course, Status, InstructionMode, ScrapedRow } from 'src/shared/types/Course';
import { Course, Status, InstructionMode, ScrapedRow, Semester } from 'src/shared/types/Course';
import { CourseSchedule } from 'src/shared/types/CourseSchedule';
import Instructor from 'src/shared/types/Instructor';
import { SiteSupport } from 'src/views/lib/getSiteSupport';
@@ -71,16 +71,6 @@ export class CourseCatalogScraper {
const [courseName, department, number] = this.separateCourseName(fullName);
const [status, isReserved] = this.getStatus(row);
// TODO: get semester from somewhere
const year = new Date().getFullYear();
const month = new Date().getMonth();
let season = 'Fall';
if (month >= 0 && month < 5) {
season = 'Spring';
} else if (month >= 5 && month < 8) {
season = 'Summer';
}
const newCourse = new Course({
fullName,
courseName,
@@ -96,11 +86,7 @@ export class CourseCatalogScraper {
instructionMode: this.getInstructionMode(row),
instructors: this.getInstructors(row) as Instructor[],
description: this.getDescription(document),
// TODO: get semester from somewhere
semester: {
year,
season,
},
semester: this.getSemester(),
});
courses.push({
element: row,
@@ -213,6 +199,43 @@ export class CourseCatalogScraper {
.filter(Boolean);
}
getSemester(): Semester {
const { pathname } = new URL(window.location.href);
const code = pathname.split('/')[4];
if (!code) {
throw new Error('Semester not found in URL');
}
let year = Number(code.substring(0, 4));
let seasonCode = Number(code.substring(4, 6));
if (!year || !seasonCode) {
throw new Error('Invalid semester found in URL');
}
let season: Semester['season'];
switch (seasonCode) {
case 2:
season = 'Spring';
break;
case 6:
season = 'Summer';
break;
case 9:
season = 'Fall';
break;
default:
throw new Error('Invalid season code');
}
return {
year,
season,
code,
};
}
/**
* Get the full name of the course from the course catalog table row (e.g. "CS 314H - Honors Discrete Structures")
* @param row the row of the course catalog table

View File

@@ -8,7 +8,7 @@ Last Updated: 03/4/2023
- [x] injecting plus header and buttons
- [x] auto loading next pages
- [x] showing course popup
- [ ] RMP, eCis, Textbook, and Syllabus buttons
- [x] RMP, Textbook, and Syllabus buttons
- [x] displaying professor information on popup
- [ ] saving courses
- [ ] Multiple schedule support
@@ -17,15 +17,15 @@ Last Updated: 03/4/2023
- [ ] Updated Easter Egg Messages
- [ ] links to RIS, Registrar, Degree Audit in browser action
- [ ] copy unique id quickly from browser action
- [ ] Clickable links to buildings
- [x] Clickable links to buildings
- [ ] Count how many hours and # of classes in schedule
- [ ] Conflict highlighting
- [ ] Tooltip that says which classes conflict, maybe suggest a different section or time that doesn't conflict
- [ ] import / export schedules from JSON file
- [ ] Search for classes from within extension
- [ ] Grade distribution
- [ ] Course description
- [ ] Highlight and use rich text to make course description more readable
- [x] Course description
- [x] Highlight and use rich text to make course description more readable
- [ ] calendar
- [ ] calendar file export
- [ ] save as png