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() {
21322132 }));
21332133
21342134 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
21352135 name: 'gotochat-floorjump',
21362136 aliases: ['floor', 'jump', 'scrollto'],
21372137 callback: async (_, index) => {
21382138 const floorIndex = Number(index);
2139-
2139+
21402140 const chatLength = typeof chat !== 'undefined' ? chat.length : -1; // Use -1 if chat is undefined to avoid errors
21412141 if (isNaN(floorIndex) || floorIndex < 0 || (chatLength !== -1 && floorIndex >= chatLength)) {
21422142 const maxIndex = (chatLength !== -1 ? chatLength - 1 : 'unknown');
21432143 toastr.warning(`Invalid message index: ${index}. Please enter a number between 0 and ${maxIndex}.`);
21442144 console.warn(`WARN: Invalid message index provided for /gotochat-floorjump: ${index}. Max index: ${maxIndex}`);
21452145 return '';
21462146 }
2147-
2147+
21482148 // --- Load all messages first to ensure the target element exists ---
21492149 console.log(`INFO: Attempting to load all messages before attempting to gotochat-floorjump ${index}.`);
21502150 try {
21512151 // Assuming showMoreMessages is available globally or within scope
21522152 await showMoreMessages(Number.MAX_SAFE_INTEGER);
21532153 console.log(`'INFO: All messages loaded (or loading initiated).`');
21542154 // Give the rendering a moment to potentially catch up after showMoreMessages
21552155 await new Promise(resolve => setTimeout(resolve, 100)); // Adjust delay if needed
21562156 } catch (error) {
@@ -2159,40 +2159,40 @@ export function initDefaultSlashCommands() {
21592159 return ''; // Exit if loading fails
21602160 }
21612161 // --- End of loading step ---
2162-
2162+
21632163 const messageElement = document.querySelector(`[mesid="${floorIndex}"]`);
2164-
2164+
21652165 if (messageElement) {
21662166 // --- Corrected: Use the actual class from the template ---
21672167 const headerElement = messageElement.querySelector('.ch_name');
21682168 const elementToScroll = headerElement || messageElement; // Fallback to the entire message div
21692169 const blockPosition = headerElement ? 'center' : 'start';
2170-
2170+
21712171 elementToScroll.scrollIntoView({ behavior: 'smooth', block: blockPosition });
2172-
2172+
21732173 // Highlight the message element
21742174 if (messageElement instanceof HTMLElement) {
21752175 if (typeof $ !== 'undefined') { // Check if jQuery is available
21762176 flashHighlight($(messageElement), 1500);
21772177 } else {
21782178 console.warn('jQuery not available, cannot use flashHighlight.');
21792179 // Optional: Add a temporary CSS class highlight if jQuery/flashHighlight is missing
21802180 messageElement.style.transition = 'background-color 0.5s ease';
21812181 messageElement.style.backgroundColor = 'yellow'; // Or some highlight color
21822182 setTimeout(() => {
21832183 messageElement.style.backgroundColor = ''; // Remove highlight
21842184 }, 1500); // Match flash duration
21852185 }
2186-
2186+
21872187 } else {
21882188 console.warn('Message element is not an HTMLElement, cannot flash highlight.');
21892189 }
2190-
2190+
2191-
2191+
21922192 } else {
21932193 // Only warn if element is not found *after* attempting to load all messages
21942194 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.`);
21952195 console.warn(`WARN: Element not found for message index ${floorIndex} using querySelector [mesid="${floorIndex}"] in /gotochat-floorjump, even after attempting to load all messages.`);
21962196 // Do NOT scroll the chat container in this case
21972197 }
21982198 return ''; // Return empty string as expected by some slash command parsers
@@ -2213,12 +2213,12 @@ export function initDefaultSlashCommands() {
22132213 A warning is displayed if the message element cannot be located even after attempting to load all messages.
22142214 </div>
22152215 <div>
22162216 <strong>Example:</strong> <pre><code>/gotochat-floorjump 10</code></pre> Scrolls to the 11th message (mesid=10).
22172217 </div>
22182218 `,
22192219 }));
2220-
2220+
22212221 const styleId = 'gotochat-floorjump-highlight-style';
22222222 if (document.getElementById(styleId)) {
22232223 document.getElementById(styleId).remove();
22242224 }