1
+
1
2
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
+ }
2
36
constructor ( ) {
3
37
this . clientConfigs = {
4
38
'google-groups' : {
@@ -11,7 +45,7 @@ class EmailClientAdapter {
11
45
subjectChange : 'input' ,
12
46
} ,
13
47
} ,
14
- gmail : {
48
+ ' gmail' : {
15
49
selectors : {
16
50
body : 'div.editable.LW-avf[contenteditable="true"][role="textbox"]' ,
17
51
subject : 'input[name="subjectbox"][tabindex="1"]' ,
@@ -21,21 +55,43 @@ class EmailClientAdapter {
21
55
subjectChange : 'input' ,
22
56
} ,
23
57
} ,
24
- outlook : {
58
+ ' outlook' : {
25
59
selectors : {
26
- body : 'div[role="textbox"][contenteditable="true"][aria-multiline="true"][aria-label="Message body, press Alt+F10 to exit"]' ,
27
- subject : 'input[aria-label="Subject"][type="text"][maxlength="255"][placeholder="Add a subject"]' ,
60
+ body : 'div[role="textbox"][contenteditable="true"][aria-multiline="true"]' ,
61
+ subject : [
62
+ 'input[aria-label="Subject"][type="text"]' ,
63
+ 'input[aria-label="Add a subject"][type="text"][role="textbox"][aria-multiline="false"]' ,
64
+ ] ,
28
65
} ,
29
66
eventTypes : {
30
67
contentChange : 'input' ,
31
68
subjectChange : 'change' ,
32
69
} ,
33
70
injectMethod : 'focusAndPaste' , // Custom injection method
34
71
} ,
35
- yahoo : {
72
+ ' yahoo' : {
36
73
selectors : {
37
- body : '#editor-container [contenteditable="true"][role="textbox"]' ,
38
- subject : 'input[placeholder="Subject"][type="text"]' ,
74
+ body : [
75
+ // Desktop selectors
76
+ '#editor-container [contenteditable="true"][role="textbox"]' ,
77
+ '[aria-multiline="true"][aria-label="Message body"][contenteditable="true"][role="textbox"]' ,
78
+ '[aria-label="Message body"][contenteditable="true"]' ,
79
+ '[role="textbox"][contenteditable="true"]' ,
80
+ '[data-test-id*="compose"][contenteditable="true"]' ,
81
+ '.compose-editor [contenteditable="true"]' ,
82
+ // Mobile selectors
83
+ '#editor-container-mobile [contenteditable="true"][role="textbox"]' ,
84
+ ] . join ( ', ' ) ,
85
+ subject : [
86
+ // Desktop selectors
87
+ '#compose-subject-input, input[placeholder="Subject"][id="compose-subject-input"]' ,
88
+ '#compose-subject-input' ,
89
+ 'input[placeholder="Subject"]' ,
90
+ 'input[aria-label*="subject" i]' ,
91
+ 'input[data-test-id*="subject" i]' ,
92
+ // Mobile selectors
93
+ '#compose-subject-input-mobile, input[placeholder="Subject"][id="compose-subject-input-mobile"]'
94
+ ] . join ( ', ' ) ,
39
95
} ,
40
96
eventTypes : {
41
97
contentChange : 'input' ,
@@ -156,4 +212,5 @@ class EmailClientAdapter {
156
212
}
157
213
158
214
// Create global instance
159
- window . emailClientAdapter = new EmailClientAdapter ( ) ;
215
+ window . emailClientAdapter = new EmailClientAdapter ( ) ;
216
+ console . log ( 'Email client adapter initialized' ) ;
0 commit comments