Simplify and improve hover handling. (#376)

This commit is contained in:
Etorix 2025-09-08 13:31:16 -07:00 • committed by GitHub
parent 1c099b8256
commit 3383bcb64b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -635,12 +635,26 @@ function renderUsername(
const hoveringMessageSet = new Set<string>();
const hoveringReactionPopoutSet = new Set<string>();
function handleHoveringMessage(message: any, animate: boolean) {
if (!message) return;
if (animate) {
addHoveringMessage(message.id);
addHoveringMessage(message.showMeYourNameGroupId);
} else {
removeHoveringMessage(message.id);
removeHoveringMessage(message.showMeYourNameGroupId);
}
}
function addHoveringMessage(id: string) {
if (!id) return;
hoveringMessageSet.add(id);
settings.store.triggerNameRerender = !settings.store.triggerNameRerender;
}
function removeHoveringMessage(id: string) {
if (!id) return;
hoveringMessageSet.delete(id);
settings.store.triggerNameRerender = !settings.store.triggerNameRerender;
}
@ -783,14 +797,21 @@ export default definePlugin({
]
},
{
// Track hovering on messages to animate mentions.
find: /setAnimate.{0,50}\.ANIMATE_CHAT_AVATAR,/,
replacement: {
// Track hovering on messages to animate names since Discord's
// built-in hover tracking is buggy. Used by a patch below.
match: /(let{setAnimate:\i}=(\i);)/,
replace: "$1if(arguments[0].message){if($2.animate){$self.addHoveringMessage(arguments[0].message.id)}else{$self.removeHoveringMessage(arguments[0].message.id)}};"
replace: "$1$self.handleHoveringMessage(arguments[0].message,$2.animate);"
}
},
{
// Attach the group ID to their messages to allow animating mentions within a group.
find: "CUSTOM_GIFT?\"\":",
replacement: {
match: /(\(\i,\i,\i\);)(let \i=\i.id===\i(?:.{0,500}?)hovering:(\i))/,
replace: "$1arguments[0].message.showMeYourNameGroupId=arguments[0].groupId;$2"
},
},
{
// Replace names in mentions.
find: ".USER_MENTION)",
@ -815,19 +836,6 @@ export default definePlugin({
replace: "$1props:arguments[2],"
}
},
{
// Track hovering over second-level messages to animate gradients.
// Tack on the groupId, which is how the client groups messages from
// the same author together, to the message temporarily so that mentions
// across a group can animate together. By default, Discord handles this,
// but moving between messages can cause a race condition where the animation
// stops on one of the messages in the group. This patch fixes that.
find: "CUSTOM_GIFT?\"\":",
replacement: {
match: /(\(\i,\i,\i\);)(let \i=\i.id===\i(?:.{0,500}?)hovering:(\i))/,
replace: "$1arguments[0].message.showMeYourNameGroupId=arguments[0].groupId;if($3){$self.addHoveringMessage(arguments[0].groupId)}else{$self.removeHoveringMessage(arguments[0].groupId)};$2"
},
},
{
// Replace names in the member list.
find: "let{colorRoleName:",
@ -936,6 +944,7 @@ export default definePlugin({
addHoveringMessage,
removeHoveringMessage,
handleHoveringMessage,
addHoveringReactionPopout,
removeHoveringReactionPopout,
getMessageNameText,