1- document . addEventListener ( 'DOMContentLoaded' , function ( ) {
1+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
22 document . getElementById ( 'btnErrorCode' ) . addEventListener ( 'click' , ( ) => {
33 chrome . tabs . create ( { url : 'https://github.com/FramedStone/SassyNic/wiki/Error-Reference' } ) ;
44 } ) ;
@@ -15,15 +15,19 @@ document.addEventListener('DOMContentLoaded', function() {
1515 chrome . tabs . create ( { url : 'https://forms.gle/SUsghNXUKW1u1US5A' } ) ;
1616 } ) ;
1717
18+ document . getElementById ( 'btnGenerateTimetable' ) . addEventListener ( 'click' , ( ) => {
19+ handleGenerateTimetable ( ) ;
20+ } ) ;
21+
1822 const termToExtractDropdown = document . getElementById ( 'termToExtractDropdown' ) ;
19- termToExtractDropdown . addEventListener ( 'toggle' , function ( ) {
23+ termToExtractDropdown . addEventListener ( 'toggle' , function ( ) {
2024 if ( termToExtractDropdown . open ) {
2125 loadTermToExtract ( ) ;
2226 }
2327 } ) ;
2428
2529 const plannerDropdown = document . getElementById ( 'plannerDropdown' ) ;
26- plannerDropdown . addEventListener ( 'toggle' , function ( ) {
30+ plannerDropdown . addEventListener ( 'toggle' , function ( ) {
2731 if ( plannerDropdown . open ) {
2832 loadPlannerOptions ( ) ;
2933 }
@@ -72,7 +76,7 @@ function loadPlannerOptions() {
7276 contentDiv . innerHTML = '<p>Loading courses...</p>' ;
7377 option . appendChild ( contentDiv ) ;
7478
75- option . addEventListener ( 'toggle' , function ( ) {
79+ option . addEventListener ( 'toggle' , function ( ) {
7680 if ( option . open ) {
7781 const dataId = option . getAttribute ( 'data-id' ) ;
7882 chrome . runtime . sendMessage ( { action : 'fetchPlannerDetail' , dataId : dataId } ) ;
@@ -164,3 +168,22 @@ function displayCourses(dataId, courses) {
164168 contentDiv . appendChild ( courseRow ) ;
165169 } ) ;
166170}
171+
172+ function handleGenerateTimetable ( ) {
173+ console . log ( 'Requesting timetable generation...' ) ;
174+
175+ chrome . runtime . sendMessage ( { action : 'generateTimetable' } , ( response ) => {
176+ if ( chrome . runtime . lastError ) {
177+ console . error ( 'Error:' , chrome . runtime . lastError . message ) ;
178+ alert ( `Error: ${ chrome . runtime . lastError . message } ` ) ;
179+ return ;
180+ }
181+
182+ if ( response ?. error ) {
183+ console . error ( 'Error generating timetable:' , response . error ) ;
184+ alert ( `Error generating timetable: ${ response . error } ` ) ;
185+ } else if ( response ?. success ) {
186+ alert ( 'Timetable generation successful! Check background console for response.' ) ;
187+ }
188+ } ) ;
189+ }
0 commit comments