-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
41 lines (33 loc) · 1.29 KB
/
functions.js
File metadata and controls
41 lines (33 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function onMessageSendHandler(event) {
console.log("HashFix: onMessageSendHandler triggered");
const item = Office.context.mailbox.item;
item.body.getAsync(Office.CoercionType.Text, function(result) {
if (result.status === Office.AsyncResultStatus.Failed) {
console.error("HashFix: Failed to get body", result.error);
event.completed({ allowEvent: true });
return;
}
const originalText = result.value;
const fixedText = fixHashtagsSimple(originalText);
if (fixedText !== originalText) {
item.body.setAsync(fixedText, { coercionType: Office.CoercionType.Text }, function(setResult) {
if (setResult.status === Office.AsyncResultStatus.Succeeded) {
console.log("HashFix: Hashtags corrected");
} else {
console.error("HashFix: Failed to set body", setResult.error);
}
event.completed({ allowEvent: true });
});
} else {
console.log("HashFix: No changes needed");
event.completed({ allowEvent: true });
}
});
}
function fixHashtagsSimple(text) {
return text.replace(/#\s+(\w+)/g, '#$1');
}
if (window.Office && Office.actions && Office.actions.associate) {
Office.actions.associate("onMessageSendHandler", onMessageSendHandler);
}
window.onMessageSendHandler = onMessageSendHandler;