Skip to content

Commit eb40c27

Browse files
authored
fix(outlook): Fix Outlook integration (#2291)
Closes #2216, #2167
1 parent c3d4f67 commit eb40c27

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

src/content/outlook.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @urlAlias outlook.office.com
44
* @urlRegex *://outlook.office.com/*
55
*/
6-
6+
77
"use strict";
88

99
// Inbox emails
@@ -16,10 +16,14 @@ togglbutton.render(
1616
'div[role="tabpanel"] div[role="group"]'
1717
)[1];
1818

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+
1924
const link = togglbutton.createTimerLink({
20-
className: `outlook`,
21-
description: () =>
22-
document.querySelector('div[role="heading"][title]').textContent
25+
className: "outlook-panel",
26+
description: getOpenedEmailSubject,
2327
});
2428

2529
container.appendChild(link);
@@ -29,21 +33,37 @@ togglbutton.render(
2933

3034
// Composing emails
3135
togglbutton.render(
32-
'[role="menubar"] .ms-CommandBar-primaryCommand:not(.toggl)',
36+
'#ReadingPaneContainerId div[data-testid="ComposeSendButton"]:not(.toggl)',
3337
{ observe: true },
3438
(elem) => {
35-
const isComposingEmail = document.querySelector('div[data-testid="ComposeSendButton"]');
39+
const composeSendButton = $('div[data-testid="ComposeSendButton"]');
3640

37-
if (isComposingEmail) {
38-
const subject = () =>
39-
document.querySelector('input.ms-TextField-field').value;
41+
if (!composeSendButton) {
42+
return;
43+
}
4044

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+
}
4551

46-
elem.appendChild(link);
52+
// If composing a new email or making a forward
53+
return document.querySelector('input.ms-TextField-field').value;
4754
}
55+
56+
const link = togglbutton.createTimerLink({
57+
className: "outlook",
58+
description: getDescription,
59+
});
60+
61+
composeSendButton.after(link);
4862
}
4963
);
64+
65+
function getOpenedEmailSubject() {
66+
const emailSubjectElement = document.querySelector('div[role="heading"][title]');
67+
68+
return emailSubjectElement ? emailSubjectElement.textContent.trim() : '';
69+
}

src/styles/style.css

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,16 +1293,17 @@ li .toggl-button.heflo {
12931293
}
12941294

12951295
/********* OUTLOOK *********/
1296-
.toggl-button.outlook {
1297-
margin-left: 10px;
1298-
color: rgb(102, 102, 102);
1296+
.toggl-button.outlook-panel {
1297+
margin: 0 5px;
12991298
text-decoration: none;
1300-
position: relative;
1301-
bottom: 3px;
1299+
display: flex !important;
1300+
justify-content: center;
1301+
align-items: center;
1302+
height: 100%;
13021303
}
13031304

1304-
.ms-CommandBar-primaryCommand .toggl-button.outlook {
1305-
align-self: center;
1305+
.toggl-button.outlook {
1306+
margin: 0 10px;
13061307
}
13071308

13081309
/********* NOTION *********/

0 commit comments

Comments
 (0)