-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions-simple.html
More file actions
74 lines (65 loc) · 2.23 KB
/
functions-simple.html
File metadata and controls
74 lines (65 loc) · 2.23 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<title>HashFix Functions</title>
<script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
</head>
<body>
<script>
// Initialize Office
Office.onReady(() => {
console.log("HashFix: Office.js loaded");
// Associate the OnSend handler
if (Office.actions && Office.actions.associate) {
Office.actions.associate("onMessageSendHandler", onMessageSendHandler);
console.log("HashFix: Handler associated");
}
});
/**
* OnMessageSend Event Handler
* Fixes hashtag formatting before sending emails
*/
function onMessageSendHandler(event) {
console.log("HashFix: onMessageSendHandler triggered");
const item = Office.context.mailbox.item;
// Get email body
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);
// Only update if changes were made
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 });
}
});
}
/**
* Simple hashtag fixing using regex
* Fixes: "# tag" -> "#tag", "# tag" -> "#tag", etc.
*/
function fixHashtagsSimple(text) {
// Replace # followed by one or more spaces with just #
return text.replace(/#\s+(\w+)/g, '#$1');
}
// Make function globally accessible
window.onMessageSendHandler = onMessageSendHandler;
console.log("HashFix: Functions loaded");
</script>
</body>
</html>