| 2159 | return ''; // Exit if loading fails | 2159 | return ''; // Exit if loading fails |
| 2160 | } | 2160 | } |
| 2161 | // --- End of loading step --- | 2161 | // --- End of loading step --- |
| 2162 | | 2162 | |
| 2163 | const messageElement = document.querySelector(`[mesid="${floorIndex}"]`); | 2163 | const messageElement = document.querySelector(`[mesid="${floorIndex}"]`); |
| 2164 | | 2164 | |
| 2165 | if (messageElement) { | 2165 | if (messageElement) { |
| 2166 | // --- Corrected: Use the actual class from the template --- | 2166 | // --- Corrected: Use the actual class from the template --- |
| 2167 | const headerElement = messageElement.querySelector('.ch_name'); | 2167 | const headerElement = messageElement.querySelector('.ch_name'); |
| 2168 | const elementToScroll = headerElement || messageElement; // Fallback to the entire message div | 2168 | const elementToScroll = headerElement || messageElement; // Fallback to the entire message div |
| 2169 | const blockPosition = headerElement ? 'center' : 'start'; | 2169 | const blockPosition = headerElement ? 'center' : 'start'; |
| 2170 | | 2170 | |
| 2171 | elementToScroll.scrollIntoView({ behavior: 'smooth', block: blockPosition }); | 2171 | elementToScroll.scrollIntoView({ behavior: 'smooth', block: blockPosition }); |
| 2172 | | 2172 | |
| 2173 | // Highlight the message element | 2173 | // Highlight the message element |
| 2174 | if (messageElement instanceof HTMLElement) { | 2174 | if (messageElement instanceof HTMLElement) { |
| 2175 | if (typeof $ !== 'undefined') { // Check if jQuery is available | 2175 | if (typeof $ !== 'undefined') { // Check if jQuery is available |
| 2176 | flashHighlight($(messageElement), 1500); | 2176 | flashHighlight($(messageElement), 1500); |
| 2177 | } else { | 2177 | } else { |
| 2178 | console.warn('jQuery not available, cannot use flashHighlight.'); | 2178 | console.warn('jQuery not available, cannot use flashHighlight.'); |
| 2179 | // Optional: Add a temporary CSS class highlight if jQuery/flashHighlight is missing | 2179 | // Optional: Add a temporary CSS class highlight if jQuery/flashHighlight is missing |
| 2180 | messageElement.style.transition = 'background-color 0.5s ease'; | 2180 | messageElement.style.transition = 'background-color 0.5s ease'; |
| 2181 | messageElement.style.backgroundColor = 'yellow'; // Or some highlight color | 2181 | messageElement.style.backgroundColor = 'yellow'; // Or some highlight color |
| 2182 | setTimeout(() => { | 2182 | setTimeout(() => { |
| 2183 | messageElement.style.backgroundColor = ''; // Remove highlight | 2183 | messageElement.style.backgroundColor = ''; // Remove highlight |
| 2184 | }, 1500); // Match flash duration | 2184 | }, 1500); // Match flash duration |
| 2185 | } | 2185 | } |
| 2186 | | 2186 | |
| 2187 | } else { | 2187 | } else { |
| 2188 | console.warn('Message element is not an HTMLElement, cannot flash highlight.'); | 2188 | console.warn('Message element is not an HTMLElement, cannot flash highlight.'); |
| 2189 | } | 2189 | } |
| 2190 | | 2190 | |
| 2191 | | 2191 | |
| 2192 | } else { | 2192 | } else { |
| 2193 | // Only warn if element is not found *after* attempting to load all messages | 2193 | // Only warn if element is not found *after* attempting to load all messages |
| 2194 | toastr.warning(`Could not find element for message ${floorIndex} (using [mesid="${floorIndex}"]) even after attempting to load all messages. It might not be rendered yet or the index is invalid.`); | 2194 | toastr.warning(`Could not find element for message ${floorIndex} (using [mesid="${floorIndex}"]) even after attempting to load all messages. It might not be rendered yet or the index is invalid.`); |
| 2195 | console.warn(`WARN: Element not found for message index ${floorIndex} using querySelector [mesid="${floorIndex}"] in /goto-floor, even after attempting to load all messages.`); | 2195 | console.warn(`WARN: Element not found for message index ${floorIndex} using querySelector [mesid="${floorIndex}"] in /chat-jump, even after attempting to load all messages.`); |
| 2196 | // Do NOT scroll the chat container in this case | 2196 | // Do NOT scroll the chat container in this case |
| 2197 | } | 2197 | } |
| 2198 | return ''; // Return empty string as expected by some slash command parsers | 2198 | return ''; // Return empty string as expected by some slash command parsers |