|
28 | 28 | margin: 0; |
29 | 29 | padding: 0; |
30 | 30 | box-sizing: border-box; |
31 | | - -webkit-tap-highlight-color: transparent; /* 移除點擊高亮 */ |
| 31 | + -webkit-tap-highlight-color: transparent; |
32 | 32 | outline: none; |
33 | 33 | } |
34 | 34 |
|
|
124 | 124 | overflow-x: auto; |
125 | 125 | } |
126 | 126 |
|
127 | | - /* === 候選字區域:修改為橫向滑動 === */ |
| 127 | + /* 候選字區域:橫向滑動 */ |
128 | 128 | #candidate-display { |
129 | | - display: flex; /* 確保內容在同一行 */ |
| 129 | + display: flex; |
130 | 130 | align-items: center; |
131 | 131 | padding: 8px; |
132 | | - gap: 12px; /* 增加間距 */ |
133 | | - white-space: nowrap; /* 內容不換行 */ |
134 | | - overflow-x: scroll; /* 允許橫向滾動 */ |
135 | | - -webkit-overflow-scrolling: touch; /* 改善 iOS 上的滑動體驗 */ |
| 132 | + gap: 12px; |
| 133 | + white-space: nowrap; |
| 134 | + overflow-x: scroll; |
| 135 | + -webkit-overflow-scrolling: touch; |
136 | 136 | min-height: 40px; |
137 | 137 | } |
138 | 138 |
|
|
148 | 148 | transition: all 0.2s; |
149 | 149 | user-select: none; |
150 | 150 | white-space: nowrap; |
151 | | - font-size: 1.2rem; /* 稍大一點的字體 */ |
152 | | - flex-shrink: 0; /* 確保文字不被壓縮 */ |
| 151 | + font-size: 1.2rem; |
| 152 | + flex-shrink: 0; |
153 | 153 | text-align: center; |
154 | 154 | } |
155 | 155 |
|
156 | 156 | #candidate-display span:active, #candidate-display span:hover { |
157 | 157 | background-color: #e8eaf6; |
158 | 158 | } |
159 | 159 |
|
160 | | - #mode-display { |
161 | | - font-size: 1rem; |
162 | | - color: #757575; |
163 | | - align-self: flex-start; |
164 | | - padding: 0 10px 10px; |
165 | | - width: 100%; |
166 | | - text-align: right; |
167 | | - } |
168 | | - |
169 | 160 | /* ------------------ 虛擬鍵盤 ------------------ */ |
170 | 161 | .keyboard-container { |
171 | 162 | width: 100%; |
|
240 | 231 | <div id="candidate-display">候選字顯示在此...</div> |
241 | 232 | </div> |
242 | 233 |
|
243 | | - <div id="mode-display">模式:三碼次常</div> |
244 | | - </div> |
| 234 | + </div> |
245 | 235 |
|
246 | 236 | <div class="keyboard-container" id="keyboard-container"> |
247 | 237 | </div> |
|
251 | 241 | let currentCodemap = {}; |
252 | 242 | let currentReverseCodemap = {}; |
253 | 243 |
|
| 244 | + // 中文模式下的鍵盤顯示 (Shift 鍵顯示為 '三碼') |
254 | 245 | const keyname_map_upper = { |
255 | 246 | 'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D', 'e': 'E', 'f': 'F', 'g': 'G', |
256 | 247 | 'h': 'H', 'i': 'I', 'j': 'J', 'k': 'K', 'l': 'L', 'm': 'M', 'n': 'N', |
257 | 248 | 'o': 'O', 'p': 'P', 'q': 'Q', 'r': 'R', 's': 'S', 't': 'T', 'u': 'U', |
258 | 249 | 'v': 'V', 'w': 'W', 'x': 'X', 'y': 'Y', 'z': 'Z', |
259 | | - // 符號對應 (按鍵顯示) |
260 | | - "'": "〃", ';': ';', ',': ',', '.': '.', '/': '/', ' ': '空白鍵', 'enter': 'Enter', 'backspace': '刪除鍵', 'shift': '中/英', |
| 250 | + // 符號對應 |
| 251 | + "'": "〃", ';': ';', ',': ',', '.': '.', '/': '/', ' ': '空白鍵', 'enter': 'Enter', 'backspace': '刪除鍵', |
| 252 | + 'shift': '三碼', // *** 修正: 中文模式顯示 '三碼' |
261 | 253 | }; |
| 254 | + // 英文模式下的鍵盤顯示 (Shift 鍵顯示為 'En') |
262 | 255 | const keyname_map_lower = { |
263 | 256 | 'a': 'a', 'b': 'b', 'c': 'c', 'd': 'd', 'e': 'e', 'f': 'f', 'g': 'g', |
264 | 257 | 'h': 'h', 'i': 'i', 'j': 'j', 'k': 'k', 'l': 'l', 'm': 'm', 'n': 'n', |
265 | 258 | 'o': 'o', 'p': 'p', 'q': 'q', 'r': 'r', 's': 's', 't': 't', 'u': 'u', |
266 | 259 | 'v': 'v', 'w': 'w', 'x': 'x', 'y': 'y', 'z': 'z', |
267 | | - "'": "'", ';': ';', ',': ',', '.': '.', '/': '/', ' ': ' ', 'enter': 'Enter', 'backspace': '刪除鍵', 'shift': '中/英', |
| 260 | + "'": "'", ';': ';', ',': ',', '.': '.', '/': '/', ' ': ' ', 'enter': 'Enter', 'backspace': '刪除鍵', |
| 261 | + 'shift': 'En', // *** 修正: 英文模式顯示 'En' |
268 | 262 | }; |
269 | 263 |
|
270 | 264 | // DOM 元素 |
271 | 265 | const textOutput = document.getElementById('text-output'); |
272 | 266 | const mainInput = document.getElementById('main-input'); |
273 | 267 | const candidateDisplay = document.getElementById('candidate-display'); |
274 | 268 | const keyboardContainer = document.getElementById('keyboard-container'); |
275 | | - const modeDisplay = document.getElementById('mode-display'); |
| 269 | + // const modeDisplay = document.getElementById('mode-display'); // 已移除 |
276 | 270 | const copyButton = document.getElementById('copy-btn'); |
277 | 271 | const clearButton = document.getElementById('clear-btn'); |
278 | 272 |
|
279 | 273 | const MAX_CODE_LENGTH = 3; |
280 | 274 | let currentCode = ''; |
281 | 275 | let currentCandidates = []; |
282 | | - // let currentPage = 0; // 已移除分頁邏輯 |
283 | | - // const candidatesPerPage = 10; // 已移除分頁邏輯 |
284 | 276 | let isEnglishMode = false; |
285 | 277 |
|
286 | 278 | function parseCinData(data) { |
|
319 | 311 | const { newCodemap, newReverseCodemap } = parseCinData(text); |
320 | 312 | currentCodemap = newCodemap; |
321 | 313 | currentReverseCodemap = newReverseCodemap; |
322 | | - updateModeDisplay(); |
| 314 | + // updateModeDisplay(); // 已移除 |
323 | 315 | mainInput.textContent = '編碼表載入成功'; |
324 | 316 | } catch (error) { |
325 | 317 | console.error(`載入 ${fileName} 時發生錯誤:`, error); |
|
346 | 338 | } |
347 | 339 | if (code === 'enter') { |
348 | 340 | if (currentCandidates.length > 0) { |
349 | | - selectCandidate(0); // 選第一個候選字上字 |
| 341 | + selectCandidate(0); |
350 | 342 | } else { |
351 | | - textOutput.textContent += '\n'; // 換行 |
| 343 | + textOutput.textContent += '\n'; |
352 | 344 | } |
353 | 345 | return; |
354 | 346 | } |
355 | 347 |
|
356 | 348 | if (code === ' ') { |
357 | 349 | if (currentCandidates.length > 0) { |
358 | | - selectCandidate(0); // 選第一個候選字上字 |
| 350 | + selectCandidate(0); |
359 | 351 | } else { |
360 | | - textOutput.textContent += ' '; // 輸出全形空格 |
| 352 | + textOutput.textContent += ' '; |
361 | 353 | } |
362 | 354 | return; |
363 | 355 | } |
|
367 | 359 | if (inputChar.match(/^[a-z;'./,<>]$/)) { |
368 | 360 | if (currentCode.length === MAX_CODE_LENGTH) { |
369 | 361 | if (currentCandidates.length > 0) { |
370 | | - selectCandidate(0); // 超過三碼,自動選第一個上字 |
| 362 | + selectCandidate(0); |
371 | 363 | } |
372 | 364 | currentCode = inputChar; |
373 | 365 | } else { |
|
412 | 404 | resetInputState(); |
413 | 405 | return; |
414 | 406 | } else if (currentCandidates.length === 0) { |
415 | | - // 如果沒有候選字,清空輸入,不做任何輸出 |
416 | 407 | resetInputState(); |
417 | 408 | return; |
418 | 409 | } |
|
421 | 412 | showCandidates(); |
422 | 413 | } |
423 | 414 |
|
424 | | - // --- 顯示候選字為**滑動列表 (已移除編號和分頁)** --- |
| 415 | + // --- 顯示候選字為滑動列表 --- |
425 | 416 | function showCandidates() { |
426 | 417 | candidateDisplay.innerHTML = ''; |
427 | 418 |
|
|
433 | 424 | return; |
434 | 425 | } |
435 | 426 |
|
436 | | - // 顯示所有候選字 |
437 | 427 | currentCandidates.forEach((candidate, index) => { |
438 | 428 | const span = document.createElement('span'); |
439 | | - // 不顯示編號 |
440 | 429 | span.textContent = candidate; |
441 | | - // 直接使用陣列索引 |
442 | 430 | span.onclick = () => selectCandidate(index); |
443 | 431 | candidateDisplay.appendChild(span); |
444 | 432 | }); |
445 | 433 |
|
446 | | - // 確保候選字滾動到最左邊 |
447 | 434 | candidateDisplay.scrollLeft = 0; |
448 | 435 | } |
449 | 436 |
|
450 | | - // --- 選擇候選字並清空輸入 (已移除分頁邏輯) --- |
| 437 | + // --- 選擇候選字並清空輸入 --- |
451 | 438 | function selectCandidate(index) { |
452 | | - // 使用絕對索引 |
453 | 439 | const selectedCandidate = currentCandidates[index]; |
454 | 440 | if (selectedCandidate) { |
455 | 441 | textOutput.textContent += selectedCandidate; |
|
461 | 447 | function resetInputState() { |
462 | 448 | currentCode = ''; |
463 | 449 | currentCandidates = []; |
464 | | - mainInput.textContent = '編碼顯示在此'; |
| 450 | + mainInput.textContent = isEnglishMode ? '英文模式' : '編碼顯示在此'; |
465 | 451 | showCandidates(); |
466 | 452 | } |
467 | 453 |
|
468 | 454 | // --- 格式化編碼顯示 --- |
469 | 455 | function formatCode(code) { |
470 | 456 | let displayString = ''; |
471 | 457 | for (const char of code) { |
472 | | - // 使用大寫字母/全形符號顯示編碼 |
473 | 458 | displayString += keyname_map_upper[char] || char.toUpperCase(); |
474 | 459 | } |
475 | 460 | return displayString; |
476 | 461 | } |
477 | 462 |
|
478 | | - // --- 更新鍵盤按鍵顯示 --- |
| 463 | + // --- 更新鍵盤按鍵顯示 (專門處理 Shift 鍵的變動) --- |
479 | 464 | function updateKeyboardDisplay() { |
480 | 465 | const map = isEnglishMode ? keyname_map_lower : keyname_map_upper; |
481 | 466 | document.querySelectorAll('.key[data-code]').forEach(keyElement => { |
|
484 | 469 | keyElement.textContent = map[code]; |
485 | 470 | } |
486 | 471 | }); |
| 472 | + |
| 473 | + // 確保 Shift 鍵在模式切換時正確顯示 |
| 474 | + const shiftKey = document.querySelector('.key[data-code="shift"]'); |
| 475 | + if (shiftKey) { |
| 476 | + shiftKey.textContent = isEnglishMode ? keyname_map_lower['shift'] : keyname_map_upper['shift']; |
| 477 | + } |
487 | 478 | } |
488 | 479 |
|
489 | | - // --- 更新模式顯示 --- |
490 | | - function updateModeDisplay() { |
491 | | - modeDisplay.textContent = isEnglishMode ? '模式:英文' : '模式:三碼次常'; |
492 | | - } |
493 | | - |
494 | 480 | // --- 動態生成手機優化鍵盤 --- |
495 | 481 | function generateMobileKeyboard() { |
496 | 482 | const layout_mobile = [ |
|
528 | 514 | } |
529 | 515 |
|
530 | 516 | key.dataset.code = code; |
| 517 | + // 初始顯示為中文模式 ('三碼') |
531 | 518 | key.textContent = keyname_map_upper[code] || keyText; |
532 | 519 |
|
533 | 520 | key.addEventListener('click', () => { |
534 | 521 | if (code === 'shift') { |
535 | 522 | isEnglishMode = !isEnglishMode; |
536 | | - updateModeDisplay(); |
| 523 | + // updateModeDisplay(); // 已移除 |
537 | 524 | updateKeyboardDisplay(); |
538 | 525 | resetInputState(); |
539 | 526 | } else if (isEnglishMode) { |
|
0 commit comments