Skip to content

Commit

Permalink
Layout fix and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TyHil committed Jan 4, 2024
1 parent 8a91e3c commit 2e306aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 0 additions & 4 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const storage = new Storage();

/** Injects the content script if we hit a course page */
chrome.webNavigation.onHistoryStateUpdated.addListener((details) => {
console.log('hello');
if (
/^.*:\/\/utdallas\.collegescheduler\.com\/terms\/.*\/courses\/.+$/.test(
details.url,
Expand Down Expand Up @@ -58,14 +57,11 @@ chrome.webNavigation.onHistoryStateUpdated.addListener((details) => {

chrome.runtime.onMessage.addListener(function (message) {
if (message === 'tableChange') {
console.log('hi');
chrome.scripting.executeScript(
{
target: {
tabId: courseTabId,
},
// content script injection only works reliably on the prod packaged extension
// b/c of the plasmo dev server connections
func: scrapeCourseData,
},
async function (resolve) {
Expand Down
8 changes: 6 additions & 2 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,26 @@ export async function scrapeCourseData() {
});
const courseRowCells = courseRow.querySelector('tr');
courseRowCells.insertBefore(newTd, courseRowCells.children[7]);
//Increase Disabled Reasons row colspan if necessary
const sectionDisabled = courseRow.querySelector('tr:nth-child(3) > td');
if (sectionDisabled !== null) {
sectionDisabled.colSpan = sectionDisabled.colSpan + 1;
}
// collapse section details
sectionDetailsButton.click();
});
return [...new Set(professors)];
}
}

export async function listenForTableChange() {
export function listenForTableChange() {
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (
mutation.type === 'attributes' &&
mutation.attributeName === 'class'
) {
if (mutation.target.classList.contains('active')) {
console.log(mutation.target.innerText.split(' ')[0]);
chrome.runtime.sendMessage('tableChange');
}
}
Expand Down

0 comments on commit 2e306aa

Please sign in to comment.