refactor(slash-commands): 优化 /goto-floor 命令的代码格式和注释 - 修正 EDLint 标记错误

6d0318eb36c864938c2abde8c3a51b391d9cfd76

awaae001 <3271436144@qq.com>

1 files changed, +9 -9Ignore whitespace
public/scripts/slash-commands.js+9 -9
@@ -2135,29 +2135,29 @@ export function initDefaultSlashCommands() {
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 input2139 // 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 message2155 const elementToScroll = headerElement || messageElement; // Prefer header, fallback to whole message
2156 const blockPosition = headerElement ? 'center' : 'start'; // Center header, else start of message2156 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(() => {
@@ -2169,7 +2169,7 @@ export function initDefaultSlashCommands() {
2169 messageElement.classList.remove('highlight-scroll', 'highlight-scroll-fadeout');2169 messageElement.classList.remove('highlight-scroll', 'highlight-scroll-fadeout');
2170 }, 500); // Matches the 0.5s transition duration2170 }, 500); // Matches the 0.5s transition duration
2171 }, 1500); // Start fade out after 1.5 seconds2171 }, 1500); // Start fade out after 1.5 seconds
2172 2172
2173 } else {2173 } else {
2174 toastr.warning(`Could not find element for message ${floorIndex} (using [mesid="${floorIndex}"]). It might not be rendered yet. Try scrolling up or use /chat-render all.`);2174 toastr.warning(`Could not find element for message ${floorIndex} (using [mesid="${floorIndex}"]). It might not be rendered yet. Try scrolling up or use /chat-render all.`);
2175 console.warn(`WARN: Element not found for message index ${floorIndex} using querySelector [mesid="${floorIndex}"] in /goto-floor.`);2175 console.warn(`WARN: Element not found for message index ${floorIndex} using querySelector [mesid="${floorIndex}"] in /goto-floor.`);
@@ -2201,7 +2201,7 @@ export function initDefaultSlashCommands() {
2201 </div>2201 </div>
2202 `,2202 `,
2203 }));2203 }));
2204 2204
2205 // --- Improved CSS for highlight ---2205 // --- Improved CSS for highlight ---
2206 const styleId = 'goto-floor-highlight-style';2206 const styleId = 'goto-floor-highlight-style';
2207 if (!document.getElementById(styleId)) {2207 if (!document.getElementById(styleId)) {