refactor(slash-commands): 重命名 goto-floor 命令为 chat-jump - 将命令名称从 'goto-floor' 修改为 'chat-jump',以更好地反映其功能

59ebf2e5b8a23080bec1ed05d152ad1c61a323ec

awaae001 <3271436144@qq.com>

1 files changed, +23 -23Ignore whitespace
public/scripts/slash-commands.js+23 -23
@@ -2132,25 +2132,25 @@ export function initDefaultSlashCommands() {
2132 }));2132 }));
21332133
2134 SlashCommandParser.addCommandObject(SlashCommand.fromProps({2134 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
2135 name: 'goto-floor',2135 name: 'chat-jump',
2136 aliases: ['floor', 'jump', 'scrollto'],2136 aliases: ['floor', 'jump', 'scrollto'],
2137 callback: async (_, index) => {2137 callback: async (_, index) => {
2138 const floorIndex = Number(index);2138 const floorIndex = Number(index);
2139 2139
2140 const chatLength = typeof chat !== 'undefined' ? chat.length : -1; // Use -1 if chat is undefined to avoid errors2140 const chatLength = typeof chat !== 'undefined' ? chat.length : -1; // Use -1 if chat is undefined to avoid errors
2141 if (isNaN(floorIndex) || floorIndex < 0 || (chatLength !== -1 && floorIndex >= chatLength)) {2141 if (isNaN(floorIndex) || floorIndex < 0 || (chatLength !== -1 && floorIndex >= chatLength)) {
2142 const maxIndex = (chatLength !== -1 ? chatLength - 1 : 'unknown');2142 const maxIndex = (chatLength !== -1 ? chatLength - 1 : 'unknown');
2143 toastr.warning(`Invalid message index: ${index}. Please enter a number between 0 and ${maxIndex}.`);2143 toastr.warning(`Invalid message index: ${index}. Please enter a number between 0 and ${maxIndex}.`);
2144 console.warn(`WARN: Invalid message index provided for /goto-floor: ${index}. Max index: ${maxIndex}`);2144 console.warn(`WARN: Invalid message index provided for /chat-jump: ${index}. Max index: ${maxIndex}`);
2145 return '';2145 return '';
2146 }2146 }
2147 2147
2148 // --- Load all messages first to ensure the target element exists ---2148 // --- Load all messages first to ensure the target element exists ---
2149 console.log(`INFO: Attempting to load all messages before attempting to goto-floor ${index}.`);2149 console.log(`INFO: Attempting to load all messages before attempting to chat-jump ${index}.`);
2150 try {2150 try {
2151 // Assuming showMoreMessages is available globally or within scope2151 // Assuming showMoreMessages is available globally or within scope
2152 await showMoreMessages(Number.MAX_SAFE_INTEGER);2152 await showMoreMessages(Number.MAX_SAFE_INTEGER);
2153 console.log(`INFO: All messages loaded (or loading initiated).`);2153 console.log('INFO: All messages loaded (or loading initiated).');
2154 // Give the rendering a moment to potentially catch up after showMoreMessages2154 // Give the rendering a moment to potentially catch up after showMoreMessages
2155 await new Promise(resolve => setTimeout(resolve, 100)); // Adjust delay if needed2155 await new Promise(resolve => setTimeout(resolve, 100)); // Adjust delay if needed
2156 } catch (error) {2156 } catch (error) {
@@ -2159,40 +2159,40 @@ export function initDefaultSlashCommands() {
2159 return ''; // Exit if loading fails2159 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 div2168 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 element2173 // Highlight the message element
2174 if (messageElement instanceof HTMLElement) {2174 if (messageElement instanceof HTMLElement) {
2175 if (typeof $ !== 'undefined') { // Check if jQuery is available2175 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 missing2179 // 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 color2181 messageElement.style.backgroundColor = 'yellow'; // Or some highlight color
2182 setTimeout(() => {2182 setTimeout(() => {
2183 messageElement.style.backgroundColor = ''; // Remove highlight2183 messageElement.style.backgroundColor = ''; // Remove highlight
2184 }, 1500); // Match flash duration2184 }, 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 messages2193 // 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 case2196 // Do NOT scroll the chat container in this case
2197 }2197 }
2198 return ''; // Return empty string as expected by some slash command parsers2198 return ''; // Return empty string as expected by some slash command parsers
@@ -2213,12 +2213,12 @@ export function initDefaultSlashCommands() {
2213 A warning is displayed if the message element cannot be located even after attempting to load all messages.2213 A warning is displayed if the message element cannot be located even after attempting to load all messages.
2214 </div>2214 </div>
2215 <div>2215 <div>
2216 <strong>Example:</strong> <pre><code>/goto-floor 10</code></pre> Scrolls to the 11th message (mesid=10).2216 <strong>Example:</strong> <pre><code>/chat-jump 10</code></pre> Scrolls to the 11th message (mesid=10).
2217 </div>2217 </div>
2218 `,2218 `,
2219 }));2219 }));
2220 2220
2221 const styleId = 'goto-floor-highlight-style';2221 const styleId = 'chat-jump-highlight-style';
2222 if (document.getElementById(styleId)) {2222 if (document.getElementById(styleId)) {
2223 document.getElementById(styleId).remove();2223 document.getElementById(styleId).remove();
2224 }2224 }