| 2135 | aliases: ['floor', 'jump', 'scrollto'], | 2135 | aliases: ['floor', 'jump', 'scrollto'], |
| 2136 | callback: async (_, index) => { | 2136 | callback: async (_, index) => { |
| 2137 | const floorIndex = Number(index); | 2137 | const floorIndex = Number(index); |
| 2138 | | 2138 | |
| 2139 | // Validate input | 2139 | // Validate input |
| 2140 | if (isNaN(floorIndex) || floorIndex < 0 || (typeof chat !== 'undefined' && floorIndex >= chat.length)) { | 2140 | if (isNaN(floorIndex) || floorIndex < 0 || (typeof chat !== 'undefined' && floorIndex >= chat.length)) { |
| 2141 | const maxIndex = (typeof chat !== 'undefined' ? chat.length - 1 : 'unknown'); | 2141 | const maxIndex = (typeof chat !== 'undefined' ? chat.length - 1 : 'unknown'); |
| 2142 | toastr.warning(`Invalid message index: ${index}. Please enter a number between 0 and ${maxIndex}.`); | 2142 | toastr.warning(`Invalid message index: ${index}. Please enter a number between 0 and ${maxIndex}.`); |
| 2143 | console.warn(`WARN: Invalid message index provided for /goto-floor: ${index}. Max index: ${maxIndex}`); | 2143 | console.warn(`WARN: Invalid message index provided for /goto-floor: ${index}. Max index: ${maxIndex}`); |
| 2144 | return ''; | 2144 | return ''; |
| 2145 | } | 2145 | } |
| 2146 | | 2146 | |
| 2147 | const messageElement = document.querySelector(`[mesid="${floorIndex}"]`); | 2147 | const messageElement = document.querySelector(`[mesid="${floorIndex}"]`); |
| 2148 | | 2148 | |
| 2149 | if (messageElement) { | 2149 | if (messageElement) { |
| 2150 | const headerElement = messageElement.querySelector('.mes_header') || | 2150 | const headerElement = messageElement.querySelector('.mes_header') || |
| 2151 | messageElement.querySelector('.mes_meta') || | 2151 | messageElement.querySelector('.mes_meta') || |
| 2152 | messageElement.querySelector('.mes_name_area') || | 2152 | messageElement.querySelector('.mes_name_area') || |
| 2153 | messageElement.querySelector('.mes_name'); | 2153 | messageElement.querySelector('.mes_name'); |
| 2154 | | 2154 | |
| 2155 | const elementToScroll = headerElement || messageElement; // Prefer header, fallback to whole message | 2155 | const elementToScroll = headerElement || messageElement; // Prefer header, fallback to whole message |
| 2156 | const blockPosition = headerElement ? 'center' : 'start'; // Center header, else start of message | 2156 | const blockPosition = headerElement ? 'center' : 'start'; // Center header, else start of message |
| 2157 | | 2157 | |
| 2158 | elementToScroll.scrollIntoView({ behavior: 'smooth', block: blockPosition }); | 2158 | elementToScroll.scrollIntoView({ behavior: 'smooth', block: blockPosition }); |
| 2159 | console.log(`INFO: Scrolled ${headerElement ? 'header of' : ''} message ${floorIndex} into view (block: ${blockPosition}).`); | 2159 | console.log(`INFO: Scrolled ${headerElement ? 'header of' : ''} message ${floorIndex} into view (block: ${blockPosition}).`); |
| 2160 | | 2160 | |
| 2161 | // --- Highlight with smooth animation --- | 2161 | // --- Highlight with smooth animation --- |
| 2162 | messageElement.classList.add('highlight-scroll'); | 2162 | messageElement.classList.add('highlight-scroll'); |
| 2163 | setTimeout(() => { | 2163 | setTimeout(() => { |