1
+ console . log ( 'Script loaded, adapter exists:' , ! ! window . emailClientAdapter ) ;
1
2
var enableToggle = true ;
2
3
function allIncluded ( outputTarget = 'email' ) {
3
4
console . log ( 'allIncluded called with outputTarget:' , outputTarget ) ;
@@ -223,6 +224,17 @@ function allIncluded(outputTarget = 'email') {
223
224
function writeScrumBody ( ) {
224
225
if ( ! enableToggle ) return ;
225
226
227
+ if ( outputTarget === 'email' ) {
228
+ if ( ! window . emailClientAdapter ) {
229
+ console . error ( 'Email client adapter not found' ) ;
230
+ return ;
231
+ }
232
+ if ( ! window . emailClientAdapter . isNewConversation ( ) ) {
233
+ console . log ( 'Not a new conversation, skipping scrum helper' ) ;
234
+ return ;
235
+ }
236
+ }
237
+
226
238
setTimeout ( ( ) => {
227
239
// Generate content first
228
240
var lastWeekUl = '<ul>' ;
@@ -291,81 +303,32 @@ ${userReason}`;
291
303
else if ( projectUrl === 'open-event' ) project = 'Open Event' ;
292
304
return project ;
293
305
}
294
- const intervalSubject = setInterval ( ( ) => {
295
- if ( ! window . emailClientAdapter ) {
296
- return ;
297
- }
298
306
299
- const elements = window . emailClientAdapter . getEditorElements ( ) ;
300
- if ( ! elements || ! elements . subject ) {
301
- return ;
302
- }
307
+ function scrumSubjectLoaded ( ) {
308
+ try {
303
309
304
-
305
- if ( ! githubUserData ) {
310
+
311
+ if ( ! enableToggle ) return ;
312
+ if ( ! scrumSubject ) {
313
+ console . error ( 'Subject element not found' ) ;
306
314
return ;
307
315
}
308
-
309
-
310
- clearInterval ( intervalSubject ) ;
311
- scrumSubject = elements . subject ;
312
-
313
- // Add a small delay to ensure the subject field is fully initialized
314
316
setTimeout ( ( ) => {
315
- scrumSubjectLoaded ( ) ;
316
- } , 100 ) ;
317
- } , 500 ) ;
318
-
319
- function scrumSubjectLoaded ( ) {
320
- try {
321
-
322
-
323
- if ( ! enableToggle ) {
324
-
325
- return ;
326
- }
327
-
328
- if ( ! scrumSubject ) {
329
-
330
- return ;
331
- }
332
-
333
- // Get the current subject value
334
- const currentSubject = scrumSubject . value || '' ;
335
-
336
-
337
- // Don't modify the subject if it's a reply or already has [Scrum]
338
- if ( currentSubject . startsWith ( 'Re:' ) ) {
339
-
340
- return ;
341
- }
342
-
343
- if ( currentSubject . includes ( '[Scrum]' ) ) {
344
-
345
- return ;
346
- }
347
-
348
- // Get user name and project
349
- const name = githubUserData . name || githubUsername ;
350
- const project = getProject ( ) ;
351
-
352
- // Format date
353
- const curDate = new Date ( ) ;
354
- const year = curDate . getFullYear ( ) . toString ( ) ;
355
- const month = ( curDate . getMonth ( ) + 1 ) . toString ( ) . padStart ( 2 , '0' ) ;
356
- const date = curDate . getDate ( ) . toString ( ) . padStart ( 2 , '0' ) ;
357
- const dateCode = year + month + date ;
358
-
359
- // Create and set new subject
360
- const newSubject = `[Scrum] ${ name } - ${ project } - ${ dateCode } - False` ;
361
- if ( window . DEBUG ) {
362
- console . log ( 'Setting new subject:' , newSubject ) ;
363
- }
364
-
365
- scrumSubject . value = newSubject ;
317
+ var name = githubUserData . name || githubUsername ;
318
+ var project = getProject ( ) ;
319
+ var curDate = new Date ( ) ;
320
+ var year = curDate . getFullYear ( ) . toString ( ) ;
321
+ var date = curDate . getDate ( ) ;
322
+ var month = curDate . getMonth ( ) ;
323
+ month ++ ;
324
+ if ( month < 10 ) month = '0' + month ;
325
+ if ( date < 10 ) date = '0' + date ;
326
+ var dateCode = year . toString ( ) + month . toString ( ) + date . toString ( ) ;
327
+ scrumSubject . value = '[Scrum] ' + name + ' - ' + project + ' - ' + dateCode + ' - False' ;
366
328
scrumSubject . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
367
- } catch ( error ) {
368
- console . error ( 'Error during subject modification:' , error ) ;
329
+ } ) ;
330
+ } catch ( err ) {
331
+ console . err ( 'Error while setting subject: ' , err ) ;
369
332
}
370
333
}
371
334
@@ -502,6 +465,25 @@ ${userReason}`;
502
465
writeScrumBody ( ) ;
503
466
} , 500 ) ;
504
467
468
+ var intervalSubject = setInterval ( ( ) => {
469
+ if ( ! githubUserData || ! window . emailClientAdapter ) return ;
470
+
471
+ const elements = window . emailClientAdapter . getEditorElements ( ) ;
472
+ if ( ! elements || ! elements . subject ) return ;
473
+
474
+ if ( outputTarget === 'email' && ! window . emailClientAdapter . isNewConversation ( ) ) {
475
+ console . log ( 'Not a new conversation, skipping subject interval' ) ;
476
+ clearInterval ( intervalSubject ) ;
477
+ return ;
478
+ }
479
+
480
+ clearInterval ( intervalSubject ) ;
481
+ scrumSubject = elements . subject ;
482
+
483
+ setTimeout ( ( ) => {
484
+ scrumSubjectLoaded ( ) ;
485
+ } , 500 ) ;
486
+ } , 500 ) ;
505
487
506
488
//check for github safe writing for both issues/prs and pr reviews
507
489
var intervalWriteGithub = setInterval ( ( ) => {
@@ -519,10 +501,4 @@ $('button>span:contains(New conversation)').parent('button').click(() => {
519
501
520
502
window . generateScrumReport = function ( ) {
521
503
allIncluded ( 'popup' ) ;
522
- } ;
523
-
524
- $ ( 'button>span:contains(New conversation)' )
525
- . parent ( 'button' )
526
- . click ( ( ) => {
527
- allIncluded ( ) ;
528
- } ) ;
504
+ } ;
0 commit comments