Skip to content

Commit 63c1916

Browse files
authored
Merge pull request #109 from vedansh-5/replyBug
fixed:scrum being injected in reply
2 parents c44a244 + d63a14e commit 63c1916

File tree

3 files changed

+91
-80
lines changed

3 files changed

+91
-80
lines changed

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"*://outlook.office.com/*",
2525
"*://mail.yahoo.com/*"
2626
],
27-
"js": ["scripts/jquery-3.2.1.min.js", "scripts/scrumHelper.js", "scripts/emailClientAdapter.js"]
27+
"js": ["scripts/jquery-3.2.1.min.js", "scripts/emailClientAdapter.js", "scripts/scrumHelper.js"]
2828
}
2929
],
3030

src/scripts/emailClientAdapter.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,38 @@
1+
12
class EmailClientAdapter {
3+
isNewConversation() {
4+
const clientType = this.detectClient();
5+
if (!clientType) return false;
6+
const elements = this.getEditorElements();
7+
if (!elements || !elements.subject) return false;
8+
const currentSubject = elements.subject.value || '';
9+
const isReplySubject = currentSubject.startsWith('Re:') || currentSubject.startsWith('Fwd:');
10+
let isReplyContext = false;
11+
12+
switch (clientType) {
13+
case 'gmail': {
14+
const editor = document.querySelector('.Am.Al.editable.LW-avf');
15+
const isNewWindow = editor ? !!editor.closest('div[role="dialog"]') : false;
16+
isReplyContext = !isNewWindow;
17+
break;
18+
}
19+
20+
case 'outlook': {
21+
isReplyContext = !!document.querySelector('[aria-label="Reply"]');
22+
break;
23+
}
24+
25+
case 'yahoo': {
26+
const header = document.querySelector('[data-test-id="compose-header-title"]');
27+
if (header) {
28+
const title = header.innerText.trim().toLowerCase();
29+
isReplyContext = title.includes('reply') || title.includes('forward');
30+
}
31+
break;
32+
}
33+
}
34+
return !(isReplySubject || isReplyContext);
35+
}
236
constructor() {
337
this.clientConfigs = {
438
'google-groups': {
@@ -11,7 +45,7 @@ class EmailClientAdapter {
1145
subjectChange: 'input',
1246
},
1347
},
14-
gmail: {
48+
'gmail': {
1549
selectors: {
1650
body: 'div.editable.LW-avf[contenteditable="true"][role="textbox"]',
1751
subject: 'input[name="subjectbox"][tabindex="1"]',
@@ -21,7 +55,7 @@ class EmailClientAdapter {
2155
subjectChange: 'input',
2256
},
2357
},
24-
outlook: {
58+
'outlook': {
2559
selectors: {
2660
body: 'div[role="textbox"][contenteditable="true"][aria-multiline="true"]',
2761
subject: [
@@ -35,7 +69,7 @@ class EmailClientAdapter {
3569
},
3670
injectMethod: 'focusAndPaste', // Custom injection method
3771
},
38-
yahoo: {
72+
'yahoo': {
3973
selectors: {
4074
body: [
4175
// Desktop selectors
@@ -179,3 +213,4 @@ class EmailClientAdapter {
179213

180214
// Create global instance
181215
window.emailClientAdapter = new EmailClientAdapter();
216+
console.log('Email client adapter initialized');

src/scripts/scrumHelper.js

Lines changed: 52 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
console.log('Script loaded, adapter exists:', !!window.emailClientAdapter);
12
var enableToggle = true;
23
function allIncluded(outputTarget = 'email') {
34
console.log('allIncluded called with outputTarget:', outputTarget);
@@ -223,6 +224,17 @@ function allIncluded(outputTarget = 'email') {
223224
function writeScrumBody() {
224225
if (!enableToggle) return;
225226

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+
226238
setTimeout(() => {
227239
// Generate content first
228240
var lastWeekUl = '<ul>';
@@ -291,81 +303,32 @@ ${userReason}`;
291303
else if (projectUrl === 'open-event') project = 'Open Event';
292304
return project;
293305
}
294-
const intervalSubject = setInterval(() => {
295-
if (!window.emailClientAdapter) {
296-
return;
297-
}
298306

299-
const elements = window.emailClientAdapter.getEditorElements();
300-
if (!elements || !elements.subject) {
301-
return;
302-
}
307+
function scrumSubjectLoaded() {
308+
try{
303309

304-
305-
if (!githubUserData) {
310+
311+
if (!enableToggle) return;
312+
if (!scrumSubject){
313+
console.error('Subject element not found');
306314
return;
307315
}
308-
309-
310-
clearInterval(intervalSubject);
311-
scrumSubject = elements.subject;
312-
313-
// Add a small delay to ensure the subject field is fully initialized
314316
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';
366328
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);
369332
}
370333
}
371334

@@ -502,6 +465,25 @@ ${userReason}`;
502465
writeScrumBody();
503466
}, 500);
504467

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);
505487

506488
//check for github safe writing for both issues/prs and pr reviews
507489
var intervalWriteGithub = setInterval(() => {
@@ -519,10 +501,4 @@ $('button>span:contains(New conversation)').parent('button').click(() => {
519501

520502
window.generateScrumReport = function() {
521503
allIncluded('popup');
522-
};
523-
524-
$('button>span:contains(New conversation)')
525-
.parent('button')
526-
.click(() => {
527-
allIncluded();
528-
});
504+
};

0 commit comments

Comments
 (0)