Skip to content

Commit

Permalink
Show profs on potential schedules
Browse files Browse the repository at this point in the history
  • Loading branch information
TyHil committed Dec 11, 2024
1 parent 54778a3 commit 53459a1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 25 deletions.
8 changes: 6 additions & 2 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ realBrowser.webNavigation.onHistoryStateUpdated.addListener((details) => {
/^.*:\/\/utdallas\.collegescheduler\.com\/terms\/.*\/currentschedule$/.test(
details.url,
);
const onPotentialSchedule =
/^.*:\/\/utdallas\.collegescheduler\.com\/terms\/.*\/schedules/.test(
details.url,
);
if (onOptions) {
//Listen for table change to rescrape data
realBrowser.tabs.sendMessage(details.tabId, 'disconnectObserver');
Expand All @@ -42,7 +46,7 @@ realBrowser.webNavigation.onHistoryStateUpdated.addListener((details) => {
func: listenForTableChange,
});
}
if (onOptions || onCurrentSchedule) {
if (onOptions || onCurrentSchedule || onPotentialSchedule) {
//Scrape data
realBrowser.scripting.executeScript(
{
Expand Down Expand Up @@ -79,7 +83,7 @@ realBrowser.webNavigation.onHistoryStateUpdated.addListener((details) => {
func: addGCalButtons,
});
}
if (!onOptions && !onCurrentSchedule) {
if (!onOptions && !onCurrentSchedule && !onPotentialSchedule) {
realBrowser.action.setBadgeText({ text: '' });
}
});
Expand Down
62 changes: 39 additions & 23 deletions src/content.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { PlasmoCSConfig } from 'plasmo';

import { type SearchQuery } from '~utils/SearchQuery';

// Plasmo CS config export
export const config: PlasmoCSConfig = {
matches: [
'https://utdallas.collegescheduler.com/terms/*/courses/*',
'https://utdallas.collegescheduler.com/terms/*/currentschedule',
'https://utdallas.collegescheduler.com/terms/*/schedules',
],
world: 'MAIN',
};
Expand Down Expand Up @@ -60,17 +62,7 @@ export async function scrapeCourseData() {
const courseTable = await waitForElement('table');
const courseRows = courseTable.querySelectorAll('tbody');

// add Professor header to the table
const newHeader = document.createElement('th');
const line1 = document.createElement('div');
line1.innerText = 'Instructor(s)';
newHeader.append(line1);
// add Skedge reminder
const line2 = document.createElement('div');
line2.style.fontWeight = 'normal';
line2.style.paddingTop = '0.5rem';
line2.innerText = 'From Skedge';
newHeader.append(line2);
// find place
const tableHeaders = courseTable.querySelector('thead > tr');
let sectionPlace;
for (
Expand All @@ -86,7 +78,22 @@ export async function scrapeCourseData() {
}
}
sectionPlace++;
tableHeaders.insertBefore(newHeader, tableHeaders.children[sectionPlace]);

if (!courseTable.querySelector('[data-skedge="th"]')) {
// add Professor header to the table
const newHeader = document.createElement('th');
newHeader.setAttribute('data-skedge', 'th');
const line1 = document.createElement('div');
line1.innerText = 'Instructor(s)';
newHeader.append(line1);
// add Skedge reminder
const line2 = document.createElement('div');
line2.style.fontWeight = 'normal';
line2.style.paddingTop = '0.5rem';
line2.innerText = 'From Skedge';
newHeader.append(line2);
tableHeaders.insertBefore(newHeader, tableHeaders.children[sectionPlace]);
}

courseRows.forEach((courseRow) => {
// get professor name from course row
Expand All @@ -96,7 +103,7 @@ export async function scrapeCourseData() {
sectionDetailsButton.click();
const sectionDetails = courseRow.querySelector('tr:nth-child(2)');
const sectionDetailsList = sectionDetails.querySelectorAll('li');
let searchQuery: SearchQuery = {};
const searchQuery: SearchQuery = {};
let professor;
sectionDetailsList.forEach((li) => {
const detailLabelText =
Expand All @@ -112,7 +119,25 @@ export async function scrapeCourseData() {
}
});
// append professor name to the table
const newTd = document.createElement('td');
const courseRowCells = courseRow.querySelector('tr');
let newTd = courseRowCells.querySelector(
'[data-skedge="td"]',
) as HTMLElement;
if (!newTd) {
newTd = document.createElement('td');
newTd.setAttribute('data-skedge', 'td');
courseRowCells.insertBefore(
newTd,
courseRowCells.children[sectionPlace],
);
//Increase Disabled Reasons row colspan if necessary
const sectionDisabled = courseRow.querySelector(
'tr:nth-child(3) > td',
) as HTMLTableCellElement | null;
if (sectionDisabled !== null) {
sectionDisabled.colSpan = sectionDisabled.colSpan + 1;
}
}
newTd.innerText = professor ?? 'No Instructor';
if (typeof professor !== 'undefined') {
// this is in case we have multiple instructions per section
Expand All @@ -126,15 +151,6 @@ export async function scrapeCourseData() {
});
});
}
const courseRowCells = courseRow.querySelector('tr');
courseRowCells.insertBefore(newTd, courseRowCells.children[sectionPlace]);
//Increase Disabled Reasons row colspan if necessary
const sectionDisabled = courseRow.querySelector(
'tr:nth-child(3) > td',
) as HTMLTableCellElement | null;
if (sectionDisabled !== null) {
sectionDisabled.colSpan = sectionDisabled.colSpan + 1;
}
// collapse section details
sectionDetailsButton.click();
});
Expand Down

0 comments on commit 53459a1

Please sign in to comment.