@@ -291,22 +291,83 @@ ${userReason}`;
291
291
else if ( projectUrl === 'open-event' ) project = 'Open Event' ;
292
292
return project ;
293
293
}
294
- function scrumSubjectLoaded ( ) {
295
- if ( ! enableToggle ) return ;
294
+ var intervalSubject = setInterval ( ( ) => {
295
+ if ( ! window . emailClientAdapter ) {
296
+ console . log ( 'Waiting for email client adapter to initialize...' ) ;
297
+ return ;
298
+ }
299
+
300
+ const elements = window . emailClientAdapter . getEditorElements ( ) ;
301
+ if ( ! elements || ! elements . subject ) {
302
+ console . log ( 'Waiting for email elements to be ready...' ) ;
303
+ return ;
304
+ }
305
+
306
+ // Only proceed if we have all required data
307
+ if ( ! githubUserData ) {
308
+ console . log ( 'Waiting for GitHub user data...' ) ;
309
+ return ;
310
+ }
311
+
312
+ console . log ( 'All requirements met, initializing subject handling' ) ;
313
+ clearInterval ( intervalSubject ) ;
314
+ scrumSubject = elements . subject ;
315
+
316
+ // Add a small delay to ensure the subject field is fully initialized
296
317
setTimeout ( ( ) => {
297
- var name = githubUserData . name || githubUsername ;
298
- var project = getProject ( ) ;
299
- var curDate = new Date ( ) ;
300
- var year = curDate . getFullYear ( ) . toString ( ) ;
301
- var date = curDate . getDate ( ) ;
302
- var month = curDate . getMonth ( ) ;
303
- month ++ ;
304
- if ( month < 10 ) month = '0' + month ;
305
- if ( date < 10 ) date = '0' + date ;
306
- var dateCode = year . toString ( ) + month . toString ( ) + date . toString ( ) ;
307
- scrumSubject . value = '[Scrum] ' + name + ' - ' + project + ' - ' + dateCode + ' - False' ;
318
+ scrumSubjectLoaded ( ) ;
319
+ } , 100 ) ;
320
+ } , 500 ) ;
321
+
322
+ function scrumSubjectLoaded ( ) {
323
+ try {
324
+ console . log ( 'Starting subject processing...' ) ;
325
+
326
+ if ( ! enableToggle ) {
327
+ console . log ( 'Subject modification skipped: extension is disabled' ) ;
328
+ return ;
329
+ }
330
+
331
+ if ( ! scrumSubject ) {
332
+ console . log ( 'Subject element not found, skipping modification' ) ;
333
+ return ;
334
+ }
335
+
336
+ // Get the current subject value
337
+ const currentSubject = scrumSubject . value || '' ;
338
+ console . log ( 'Current subject:' , currentSubject ) ;
339
+
340
+ // Don't modify the subject if it's a reply or already has [Scrum]
341
+ if ( currentSubject . startsWith ( 'Re:' ) ) {
342
+ console . log ( 'Subject modification skipped: this is a reply email' ) ;
343
+ return ;
344
+ }
345
+
346
+ if ( currentSubject . includes ( '[Scrum]' ) ) {
347
+ console . log ( 'Subject modification skipped: already contains [Scrum]' ) ;
348
+ return ;
349
+ }
350
+
351
+ // Get user name and project
352
+ const name = githubUserData . name || githubUsername ;
353
+ const project = getProject ( ) ;
354
+
355
+ // Format date
356
+ const curDate = new Date ( ) ;
357
+ const year = curDate . getFullYear ( ) . toString ( ) ;
358
+ const month = ( curDate . getMonth ( ) + 1 ) . toString ( ) . padStart ( 2 , '0' ) ;
359
+ const date = curDate . getDate ( ) . toString ( ) . padStart ( 2 , '0' ) ;
360
+ const dateCode = year + month + date ;
361
+
362
+ // Create and set new subject
363
+ const newSubject = `[Scrum] ${ name } - ${ project } - ${ dateCode } - False` ;
364
+ console . log ( 'Setting new subject:' , newSubject ) ;
365
+
366
+ scrumSubject . value = newSubject ;
308
367
scrumSubject . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
309
- } ) ;
368
+ } catch ( error ) {
369
+ console . error ( 'Error during subject modification:' , error ) ;
370
+ }
310
371
}
311
372
312
373
function writeGithubPrsReviews ( ) {
@@ -442,16 +503,6 @@ ${userReason}`;
442
503
writeScrumBody ( ) ;
443
504
} , 500 ) ;
444
505
445
- var intervalSubject = setInterval ( ( ) => {
446
- if ( ! githubUserData || ! window . emailClientAdapter ) return ;
447
-
448
- const elements = window . emailClientAdapter . getEditorElements ( ) ;
449
- if ( ! elements || ! elements . subject ) return ;
450
-
451
- clearInterval ( intervalSubject ) ;
452
- scrumSubject = elements . subject ;
453
- scrumSubjectLoaded ( ) ;
454
- } , 500 ) ;
455
506
456
507
//check for github safe writing for both issues/prs and pr reviews
457
508
var intervalWriteGithub = setInterval ( ( ) => {
0 commit comments