3
3
* @urlAlias outlook.office.com
4
4
* @urlRegex *://outlook.office.com/*
5
5
*/
6
-
6
+
7
7
"use strict" ;
8
8
9
9
// Inbox emails
@@ -16,10 +16,14 @@ togglbutton.render(
16
16
'div[role="tabpanel"] div[role="group"]'
17
17
) [ 1 ] ;
18
18
19
+ // If the container is not found or the button is already there, do nothing
20
+ if ( ! container || container . querySelector ( '.toggl-button' ) ) {
21
+ return ;
22
+ }
23
+
19
24
const link = togglbutton . createTimerLink ( {
20
- className : `outlook` ,
21
- description : ( ) =>
22
- document . querySelector ( 'div[role="heading"][title]' ) . textContent
25
+ className : "outlook-panel" ,
26
+ description : getOpenedEmailSubject ,
23
27
} ) ;
24
28
25
29
container . appendChild ( link ) ;
@@ -29,21 +33,37 @@ togglbutton.render(
29
33
30
34
// Composing emails
31
35
togglbutton . render (
32
- '[role="menubar"] .ms-CommandBar-primaryCommand :not(.toggl)' ,
36
+ '#ReadingPaneContainerId div[data-testid="ComposeSendButton"] :not(.toggl)' ,
33
37
{ observe : true } ,
34
38
( elem ) => {
35
- const isComposingEmail = document . querySelector ( 'div[data-testid="ComposeSendButton"]' ) ;
39
+ const composeSendButton = $ ( 'div[data-testid="ComposeSendButton"]' ) ;
36
40
37
- if ( isComposingEmail ) {
38
- const subject = ( ) =>
39
- document . querySelector ( 'input.ms-TextField-field' ) . value ;
41
+ if ( ! composeSendButton ) {
42
+ return ;
43
+ }
40
44
41
- const link = togglbutton . createTimerLink ( {
42
- className : "outlook" ,
43
- description : subject ,
44
- } ) ;
45
+ function getDescription ( ) {
46
+ // If making a reply, the subject is already filled
47
+ const emailSubject = getOpenedEmailSubject ( ) ;
48
+ if ( emailSubject ) {
49
+ return emailSubject ;
50
+ }
45
51
46
- elem . appendChild ( link ) ;
52
+ // If composing a new email or making a forward
53
+ return document . querySelector ( 'input.ms-TextField-field' ) . value ;
47
54
}
55
+
56
+ const link = togglbutton . createTimerLink ( {
57
+ className : "outlook" ,
58
+ description : getDescription ,
59
+ } ) ;
60
+
61
+ composeSendButton . after ( link ) ;
48
62
}
49
63
) ;
64
+
65
+ function getOpenedEmailSubject ( ) {
66
+ const emailSubjectElement = document . querySelector ( 'div[role="heading"][title]' ) ;
67
+
68
+ return emailSubjectElement ? emailSubjectElement . textContent . trim ( ) : '' ;
69
+ }
0 commit comments