textbook button, properly scraping the semester (year and season) from the url"
This commit is contained in:
@@ -25,7 +25,9 @@ export type Semester = {
|
|||||||
/** The year that the semester is in */
|
/** The year that the semester is in */
|
||||||
year: number;
|
year: number;
|
||||||
/** The season that the semester is in (Fall, Spring, Summer) */
|
/** The season that the semester is in (Fall, Spring, Summer) */
|
||||||
season: string;
|
season: 'Fall' | 'Spring' | 'Summer';
|
||||||
|
/** UT's code for the semester */
|
||||||
|
code: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -53,6 +53,14 @@ export default function CourseButtons({ course }: Props) {
|
|||||||
openNewTab({ url: url.toString() });
|
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 (
|
return (
|
||||||
<Card className={styles.container}>
|
<Card className={styles.container}>
|
||||||
<Button
|
<Button
|
||||||
@@ -72,7 +80,7 @@ export default function CourseButtons({ course }: Props) {
|
|||||||
</Text>
|
</Text>
|
||||||
<Icon className={styles.icon} color='white' name='grading' size='medium' />
|
<Icon className={styles.icon} color='white' name='grading' size='medium' />
|
||||||
</Button>
|
</Button>
|
||||||
<Button type='tertiary' className={styles.button}>
|
<Button onClick={openTextbookURL} type='tertiary' className={styles.button}>
|
||||||
<Text size='medium' weight='regular' color='white'>
|
<Text size='medium' weight='regular' color='white'>
|
||||||
Textbook
|
Textbook
|
||||||
</Text>
|
</Text>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Serialized } from 'chrome-extension-toolkit';
|
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 { CourseSchedule } from 'src/shared/types/CourseSchedule';
|
||||||
import Instructor from 'src/shared/types/Instructor';
|
import Instructor from 'src/shared/types/Instructor';
|
||||||
import { SiteSupport } from 'src/views/lib/getSiteSupport';
|
import { SiteSupport } from 'src/views/lib/getSiteSupport';
|
||||||
@@ -71,16 +71,6 @@ export class CourseCatalogScraper {
|
|||||||
const [courseName, department, number] = this.separateCourseName(fullName);
|
const [courseName, department, number] = this.separateCourseName(fullName);
|
||||||
const [status, isReserved] = this.getStatus(row);
|
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({
|
const newCourse = new Course({
|
||||||
fullName,
|
fullName,
|
||||||
courseName,
|
courseName,
|
||||||
@@ -96,11 +86,7 @@ export class CourseCatalogScraper {
|
|||||||
instructionMode: this.getInstructionMode(row),
|
instructionMode: this.getInstructionMode(row),
|
||||||
instructors: this.getInstructors(row) as Instructor[],
|
instructors: this.getInstructors(row) as Instructor[],
|
||||||
description: this.getDescription(document),
|
description: this.getDescription(document),
|
||||||
// TODO: get semester from somewhere
|
semester: this.getSemester(),
|
||||||
semester: {
|
|
||||||
year,
|
|
||||||
season,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
courses.push({
|
courses.push({
|
||||||
element: row,
|
element: row,
|
||||||
@@ -213,6 +199,43 @@ export class CourseCatalogScraper {
|
|||||||
.filter(Boolean);
|
.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")
|
* 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
|
* @param row the row of the course catalog table
|
||||||
|
|||||||
8
todo.md
8
todo.md
@@ -8,7 +8,7 @@ Last Updated: 03/4/2023
|
|||||||
- [x] injecting plus header and buttons
|
- [x] injecting plus header and buttons
|
||||||
- [x] auto loading next pages
|
- [x] auto loading next pages
|
||||||
- [x] showing course popup
|
- [x] showing course popup
|
||||||
- [ ] RMP, eCis, Textbook, and Syllabus buttons
|
- [x] RMP, Textbook, and Syllabus buttons
|
||||||
- [x] displaying professor information on popup
|
- [x] displaying professor information on popup
|
||||||
- [ ] saving courses
|
- [ ] saving courses
|
||||||
- [ ] Multiple schedule support
|
- [ ] Multiple schedule support
|
||||||
@@ -17,15 +17,15 @@ Last Updated: 03/4/2023
|
|||||||
- [ ] Updated Easter Egg Messages
|
- [ ] Updated Easter Egg Messages
|
||||||
- [ ] links to RIS, Registrar, Degree Audit in browser action
|
- [ ] links to RIS, Registrar, Degree Audit in browser action
|
||||||
- [ ] copy unique id quickly from 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
|
- [ ] Count how many hours and # of classes in schedule
|
||||||
- [ ] Conflict highlighting
|
- [ ] Conflict highlighting
|
||||||
- [ ] Tooltip that says which classes conflict, maybe suggest a different section or time that doesn't conflict
|
- [ ] Tooltip that says which classes conflict, maybe suggest a different section or time that doesn't conflict
|
||||||
- [ ] import / export schedules from JSON file
|
- [ ] import / export schedules from JSON file
|
||||||
- [ ] Search for classes from within extension
|
- [ ] Search for classes from within extension
|
||||||
- [ ] Grade distribution
|
- [ ] Grade distribution
|
||||||
- [ ] Course description
|
- [x] Course description
|
||||||
- [ ] Highlight and use rich text to make course description more readable
|
- [x] Highlight and use rich text to make course description more readable
|
||||||
- [ ] calendar
|
- [ ] calendar
|
||||||
- [ ] calendar file export
|
- [ ] calendar file export
|
||||||
- [ ] save as png
|
- [ ] save as png
|
||||||
|
|||||||
Reference in New Issue
Block a user