@@ -79,6 +79,7 @@ export class GmailElementReplacer extends WebmailElementReplacer {
79
79
super ( ) ;
80
80
this . webmailCommon = new WebmailCommon ( acctEmail , injector ) ;
81
81
this . pubLookup = new PubLookup ( clientConfiguration ) ;
82
+ this . setupSecureActionsOnGmailMenu ( ) ;
82
83
}
83
84
84
85
public getIntervalFunctions = ( ) : IntervalFunction [ ] => {
@@ -148,14 +149,14 @@ export class GmailElementReplacer extends WebmailElementReplacer {
148
149
}
149
150
} ;
150
151
151
- public addSecureActionsToMessageMenu = ( ) => {
152
- $ ( document ) . on ( 'click' , 'div.aHU.hx' , event => {
153
- const $actionsBtn = $ ( event . currentTarget ) . find ( this . sel . msgActionsBtn ) ;
154
- if ( $actionsBtn . length && ! $ ( '.action_menu_message_button' ) . length ) {
155
- this . addMenuButton ( 'reply' , '#r' ) ;
156
- this . addMenuButton ( 'forward' , '#r3' ) ;
152
+ public setupSecureActionsOnGmailMenu = ( ) => {
153
+ const observer = new MutationObserver ( ( ) => {
154
+ const gmailActionsMenu = document . querySelector ( this . sel . msgActionsMenu ) ;
155
+ if ( gmailActionsMenu && ( gmailActionsMenu as HTMLElement ) . offsetParent !== undefined ) {
156
+ this . addSecureActionsToMessageMenu ( ) ;
157
157
}
158
158
} ) ;
159
+ observer . observe ( document . body , { childList : true , subtree : true } ) ;
159
160
} ;
160
161
161
162
private everything = ( ) => {
@@ -291,13 +292,14 @@ export class GmailElementReplacer extends WebmailElementReplacer {
291
292
return ! ! $ ( 'iframe.pgp_block' ) . filter ( ':visible' ) . length ;
292
293
} ;
293
294
294
- private addMenuButton = ( action : 'reply' | 'forward' , selector : string ) => {
295
- const gmailActionsMenuContainer = $ ( this . sel . msgActionsMenu ) . find ( selector ) ;
296
- const button = $ ( this . factory . actionsMenuBtn ( action ) ) . insertAfter ( gmailActionsMenuContainer ) ; // xss-safe-factory
297
- button . on (
298
- 'click' ,
299
- Ui . event . handle ( ( el , ev : JQuery . Event ) => this . actionActivateSecureReplyHandler ( el , ev ) )
300
- ) ;
295
+ private addMenuButton = ( replyOption : ReplyOption , gmailContextMenuBtn : string ) => {
296
+ if ( $ ( gmailContextMenuBtn ) . is ( ':visible' ) ) {
297
+ const button = $ ( this . factory . btnSecureMenuBtn ( replyOption ) ) . insertAfter ( gmailContextMenuBtn ) ; // xss-safe-factory
298
+ button . on (
299
+ 'click' ,
300
+ Ui . event . handle ( ( el , ev : JQuery . Event ) => this . actionActivateSecureReplyHandler ( el , ev ) )
301
+ ) ;
302
+ }
301
303
} ;
302
304
303
305
private replaceConvoBtns = ( force = false ) => {
@@ -371,7 +373,14 @@ export class GmailElementReplacer extends WebmailElementReplacer {
371
373
private actionActivateSecureReplyHandler = async ( btn : HTMLElement , event : JQuery . Event ) => {
372
374
event . stopImmediatePropagation ( ) ;
373
375
const secureReplyInvokedFromMenu = btn . className . includes ( 'action_menu_message_button' ) ;
374
- const replyOption : ReplyOption = btn . className . includes ( 'reply' ) ? 'a_reply' : 'a_forward' ;
376
+ let replyOption : ReplyOption ;
377
+ if ( btn . className . includes ( 'reply-all' ) ) {
378
+ replyOption = 'a_reply_all' ;
379
+ } else if ( btn . className . includes ( 'forward' ) ) {
380
+ replyOption = 'a_forward' ;
381
+ } else {
382
+ replyOption = 'a_reply' ;
383
+ }
375
384
if ( $ ( '#switch_to_encrypted_reply' ) . length ) {
376
385
$ ( '#switch_to_encrypted_reply' ) . trigger ( 'click' ) ;
377
386
return ;
@@ -922,4 +931,13 @@ export class GmailElementReplacer extends WebmailElementReplacer {
922
931
}
923
932
}
924
933
} ;
934
+
935
+ private addSecureActionsToMessageMenu = ( ) => {
936
+ if ( $ ( '.action_menu_message_button' ) . length ) {
937
+ return ;
938
+ }
939
+ this . addMenuButton ( 'a_reply' , '#r' ) ;
940
+ this . addMenuButton ( 'a_reply_all' , '#r2' ) ;
941
+ this . addMenuButton ( 'a_forward' , '#r3' ) ;
942
+ } ;
925
943
}
0 commit comments