Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
addGCalButtons,
listenForTableChange,
scrapeCourseData,
} from '~content';
} from '~contents/galaxy';
import { neededOrigins } from '~data/config';
import { type SearchQuery } from '~types/SearchQuery';

Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions src/contents/trends-listener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { PlasmoCSConfig } from 'plasmo';

// Storage prototype is only available in the main world

export const config: PlasmoCSConfig = {
matches: ['https://trends.utdnebula.com/*'],
world: 'MAIN',
};

const originalSetItem = Storage.prototype.setItem.bind(localStorage);

Storage.prototype.setItem = (key, value) => {
originalSetItem(key, value);
window.dispatchEvent(new Event('planner-updated'));
};
46 changes: 46 additions & 0 deletions src/contents/trends.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Storage } from '@plasmohq/storage';
import type { PlasmoCSConfig } from 'plasmo';

export interface ClassData {
query: {
prefix: string;
number: string;
profFirst?: string;
profLast?: string;
sectionNumbers?: string[];
};
semester: string;
}

// Trends localStorage format:
// { query: { prefix, number, profFirst, profLast, sectionNumbers: string[] }, semester }

export const config: PlasmoCSConfig = {
matches: ['https://trends.utdnebula.com/*'],
};

const storage = new Storage();

export async function fetchFromTrends() {
const classes = window.localStorage.getItem('planner_v2');
const parsedClasses = JSON.parse(classes);
const filteredClasses = parsedClasses.filter((entry: ClassData) => {
// Only add current semester classes with a specific section
return (
entry.query.prefix &&
entry.query.number &&
entry.semester &&
entry.semester === '26F' &&
entry.query.sectionNumbers &&
entry.query.sectionNumbers.length > 0
);
});
storage.set('planner_v2_classData', filteredClasses);
console.log('Updated planner_v2_classData with new data:', filteredClasses);
}

// Listen for changes to localStorage
window.addEventListener('planner-updated', fetchFromTrends);

// When extensions load, fetch the data from Trends
fetchFromTrends();
Loading