From d76cb37beb511d4b57294eeff18222ef651a56b7 Mon Sep 17 00:00:00 2001 From: davis118 Date: Tue, 15 Sep 2026 19:49:50 -0500 Subject: [PATCH 1/5] add trends content script to save planner_v2 into Plasmo storage --- src/background/index.ts | 2 +- src/{content.ts => contents/galaxy.ts} | 0 src/contents/trends.ts | 13 +++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) rename src/{content.ts => contents/galaxy.ts} (100%) create mode 100644 src/contents/trends.ts diff --git a/src/background/index.ts b/src/background/index.ts index 0b20fe5..51b6c3e 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -3,7 +3,7 @@ import { addGCalButtons, listenForTableChange, scrapeCourseData, -} from '~content'; +} from '~contents/galaxy'; import { neededOrigins } from '~data/config'; import { type SearchQuery } from '~types/SearchQuery'; diff --git a/src/content.ts b/src/contents/galaxy.ts similarity index 100% rename from src/content.ts rename to src/contents/galaxy.ts diff --git a/src/contents/trends.ts b/src/contents/trends.ts new file mode 100644 index 0000000..2240a95 --- /dev/null +++ b/src/contents/trends.ts @@ -0,0 +1,13 @@ +import type { PlasmoCSConfig } from 'plasmo'; + +export const config: PlasmoCSConfig = { + matches: ['https://trends.utdnebula.com/'], + world: 'MAIN', +}; + +const classData = window.localStorage.getItem('planner_v2'); + +const storage = new Storage(); +storage.set('classData', classData); + +console.log(classData); From 8de8a8902a9c442add6889c2284b1f44840eac31 Mon Sep 17 00:00:00 2001 From: davis118 Date: Wed, 16 Sep 2026 15:10:17 -0500 Subject: [PATCH 2/5] filter for valid classes and store as ClassData type. --- src/contents/trends.ts | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/contents/trends.ts b/src/contents/trends.ts index 2240a95..e42ceb3 100644 --- a/src/contents/trends.ts +++ b/src/contents/trends.ts @@ -1,13 +1,40 @@ +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/'], world: 'MAIN', }; -const classData = window.localStorage.getItem('planner_v2'); - const storage = new Storage(); -storage.set('classData', classData); -console.log(classData); +export async function fetchFromTrends() { + let classes = window.localStorage.getItem('planner_v2'); + JSON.parse(classes).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', classes); + console.log(classes); +} \ No newline at end of file From 08742c6b9af78d511ae3d3870cfda0530c7d6d1b Mon Sep 17 00:00:00 2001 From: davis118 Date: Wed, 16 Sep 2026 16:06:49 -0500 Subject: [PATCH 3/5] fetch on both page load and update --- src/contents/trends-listener.ts | 16 ++++++++++++++++ src/contents/trends.ts | 21 ++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 src/contents/trends-listener.ts diff --git a/src/contents/trends-listener.ts b/src/contents/trends-listener.ts new file mode 100644 index 0000000..5d7ad05 --- /dev/null +++ b/src/contents/trends-listener.ts @@ -0,0 +1,16 @@ +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')); +}; \ No newline at end of file diff --git a/src/contents/trends.ts b/src/contents/trends.ts index e42ceb3..bca5d1a 100644 --- a/src/contents/trends.ts +++ b/src/contents/trends.ts @@ -1,6 +1,7 @@ import { Storage } from '@plasmohq/storage'; import type { PlasmoCSConfig } from 'plasmo'; + export interface ClassData { query: { prefix: string; @@ -16,15 +17,15 @@ export interface ClassData { // { query: { prefix, number, profFirst, profLast, sectionNumbers: string[] }, semester } export const config: PlasmoCSConfig = { - matches: ['https://trends.utdnebula.com/'], - world: 'MAIN', + matches: ['https://trends.utdnebula.com/*'], }; const storage = new Storage(); export async function fetchFromTrends() { - let classes = window.localStorage.getItem('planner_v2'); - JSON.parse(classes).filter((entry: ClassData) => { + 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 && @@ -35,6 +36,12 @@ export async function fetchFromTrends() { entry.query.sectionNumbers.length > 0 ); }); - storage.set('planner_v2_classData', classes); - console.log(classes); -} \ No newline at end of file + 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() \ No newline at end of file From 782737fd4afd9ffa4d85167d12d614af804f3cf4 Mon Sep 17 00:00:00 2001 From: davis118 Date: Wed, 16 Sep 2026 16:21:29 -0500 Subject: [PATCH 4/5] npm run format --- src/contents/trends-listener.ts | 3 +-- src/contents/trends.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/contents/trends-listener.ts b/src/contents/trends-listener.ts index 5d7ad05..1fc5e1c 100644 --- a/src/contents/trends-listener.ts +++ b/src/contents/trends-listener.ts @@ -1,6 +1,5 @@ import type { PlasmoCSConfig } from 'plasmo'; - // Storage prototype is only available in the main world export const config: PlasmoCSConfig = { @@ -13,4 +12,4 @@ const originalSetItem = Storage.prototype.setItem.bind(localStorage); Storage.prototype.setItem = (key, value) => { originalSetItem(key, value); window.dispatchEvent(new Event('planner-updated')); -}; \ No newline at end of file +}; diff --git a/src/contents/trends.ts b/src/contents/trends.ts index bca5d1a..85f5618 100644 --- a/src/contents/trends.ts +++ b/src/contents/trends.ts @@ -1,7 +1,6 @@ import { Storage } from '@plasmohq/storage'; import type { PlasmoCSConfig } from 'plasmo'; - export interface ClassData { query: { prefix: string; @@ -44,4 +43,4 @@ export async function fetchFromTrends() { window.addEventListener('planner-updated', fetchFromTrends); // When extensions load, fetch the data from Trends -fetchFromTrends() \ No newline at end of file +fetchFromTrends(); From d8846c0a357e0f5a90eb8b4fd55dc4f6feecec57 Mon Sep 17 00:00:00 2001 From: davis118 Date: Tue, 22 Sep 2026 19:28:01 -0500 Subject: [PATCH 5/5] remove hardcoded 26F semester --- src/contents/trends.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/contents/trends.ts b/src/contents/trends.ts index 85f5618..cddc744 100644 --- a/src/contents/trends.ts +++ b/src/contents/trends.ts @@ -21,6 +21,14 @@ export const config: PlasmoCSConfig = { const storage = new Storage(); +export function getCurrentSemester(): ClassData['semester'] { + const today = new Date(); + const year = today.getFullYear() % 100; + const month = today.getMonth(); + const semester = month < 5 ? 'S' : month < 8 ? 'U' : 'F'; + return `${year}${semester}` as ClassData['semester']; +} + export async function fetchFromTrends() { const classes = window.localStorage.getItem('planner_v2'); const parsedClasses = JSON.parse(classes); @@ -30,13 +38,14 @@ export async function fetchFromTrends() { entry.query.prefix && entry.query.number && entry.semester && - entry.semester === '26F' && + entry.semester === getCurrentSemester() && entry.query.sectionNumbers && entry.query.sectionNumbers.length > 0 ); }); storage.set('planner_v2_classData', filteredClasses); console.log('Updated planner_v2_classData with new data:', filteredClasses); + console.log('Current semester:', getCurrentSemester()); } // Listen for changes to localStorage