-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat-indicators.js
More file actions
69 lines (54 loc) · 2.52 KB
/
Copy pathchat-indicators.js
File metadata and controls
69 lines (54 loc) · 2.52 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
Hooks.on("renderChatMessage", (chatMessage, html, messageData) => {
injectMessageTag(html, messageData);
injectWhisperParticipants(html, messageData);
});
function injectMessageTag(html, messageData) {
const timestampTag = html.find(".message-timestamp");
const indicatorElement = $("<span>");
indicatorElement.addClass("chat-mode-indicator");
const whisperTargets = messageData.message.whisper;
const isBlind = messageData.message.blind || false;
const isWhisper = whisperTargets?.length > 0 || false;
const isSelf = isWhisper && whisperTargets.length === 1 && whisperTargets[0] === messageData.message.user;
const isRoll = messageData.message.roll !== undefined;
// Inject tag to the left of the timestamp
if (isBlind) {
indicatorElement.text(game.i18n.localize("CHAT.RollBlind"));
timestampTag.before(indicatorElement);
} else if (isSelf && whisperTargets[0]) {
indicatorElement.text(game.i18n.localize("CHAT.RollSelf"));
timestampTag.before(indicatorElement);
} else if (isRoll && isWhisper) {
indicatorElement.text(game.i18n.localize("CHAT.RollPrivate"));
timestampTag.before(indicatorElement);
} else if (isWhisper) {
indicatorElement.text(game.i18n.localize("chat-indicators.Whisper"));
timestampTag.before(indicatorElement);
}
}
function injectWhisperParticipants(html, messageData) {
const alias = messageData.alias;
const whisperTargetString = messageData.whisperTo;
const whisperTargetIds = messageData.message.whisper;
const isWhisper = whisperTargetIds?.length > 0 || false;
const isRoll = messageData.message.roll !== undefined;
const authorId = messageData.message.user;
const userId = game.user.data._id;
if (!isWhisper) return;
if (userId !== authorId && !whisperTargetIds.includes(userId) ) return;
// remove the old whisper to content, if it exists
html.find(".whisper-to").detach();
// if this is a roll
if (isRoll) return;
// add new content
const messageHeader = html.find(".message-header");
const whisperParticipants = $("<span>");
whisperParticipants.addClass("whisper-to");
const whisperFrom = $("<span>");
whisperFrom.text(`${game.i18n.localize("chat-indicators.From")}: ${alias}`);
const whisperTo = $("<span>");
whisperTo.text(`${game.i18n.localize("CHAT.To")}: ${whisperTargetString}`);
whisperParticipants.append(whisperFrom);
whisperParticipants.append(whisperTo);
messageHeader.append(whisperParticipants);
}