refactor: Cache jQuery html object for consistent DOM manipulation in hooks.

This commit is contained in:
CPTN Cosmo 2026-02-10 03:22:25 +01:00
parent 64463504d5
commit fe9233cae2
No known key found for this signature in database

View file

@ -51,8 +51,9 @@ Hooks.once('init', () => {
// Hook to handle conditional settings in the UI // Hook to handle conditional settings in the UI
Hooks.on('renderSettingsConfig', (app, html, data) => { Hooks.on('renderSettingsConfig', (app, html, data) => {
// Search for our specific inputs with safer selectors (ending with key) // Search for our specific inputs with safer selectors (ending with key)
const animSelect = html.find('select[name$="critAnimation"]'); const $html = $(html);
const colorInput = html.find('input[name$="pulseColor"]'); const animSelect = $html.find('select[name$="critAnimation"]');
const colorInput = $html.find('input[name$="pulseColor"]');
// Ensure we found the color input to transform it // Ensure we found the color input to transform it
if (colorInput.length) { if (colorInput.length) {
@ -130,7 +131,8 @@ Hooks.on('renderChatMessage', (message, html, data) => {
if (isCriticalHit(roll)) { if (isCriticalHit(roll)) {
const anim = game.settings.get('dh-immersive-crits', 'critAnimation'); const anim = game.settings.get('dh-immersive-crits', 'critAnimation');
if (anim && anim !== 'none') { if (anim && anim !== 'none') {
const content = html.find('.message-content'); const $html = $(html);
const content = $html.find('.message-content');
content.addClass(`dh-crit-${anim}`); content.addClass(`dh-crit-${anim}`);
// Apply custom color for Pulse // Apply custom color for Pulse
@ -173,7 +175,7 @@ Hooks.on('renderChatMessage', (message, html, data) => {
} }
// Also add a general class for easier targeting if needed // Also add a general class for easier targeting if needed
html.addClass('dh-critical-hit'); $html.addClass('dh-critical-hit');
} }
} }
}); });