|
9 | 9 | <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;700&display=swap" rel="stylesheet"> |
10 | 10 | <style> |
11 | 11 | /* ----------------------------------------------------- */ |
12 | | - /* 樣式定義 */ |
| 12 | + /* 樣式定義 (未變動) */ |
13 | 13 | /* ----------------------------------------------------- */ |
14 | 14 |
|
15 | 15 | :root { |
|
38 | 38 | align-items: center; |
39 | 39 | background-color: var(--background-color); |
40 | 40 | min-height: 100vh; |
41 | | - /* 保持足夠的底部空間以容納鍵盤 */ |
42 | 41 | padding-bottom: 490px; |
43 | 42 | } |
44 | 43 |
|
|
313 | 312 | </div> |
314 | 313 |
|
315 | 314 | <div class="search-area"> |
316 | | - <input type="text" id="search-input" placeholder="在此輸入漢字 (1字)" maxlength="1"> |
| 315 | + <input type="text" id="search-input" placeholder="在此輸入字符 (1字)" maxlength="1"> |
317 | 316 | <div id="search-result">查詢結果顯示在此</div> |
318 | 317 | </div> |
319 | 318 | <div id="app-container"> |
|
343 | 342 | const CURSOR_HTML = '<span id="main-cursor" class="cursor">\u200c</span>'; |
344 | 343 | const NON_BREAK_ANCHOR = '\ufeff'; |
345 | 344 |
|
346 | | - // --- 鍵盤顯示內容映射表 --- |
| 345 | + // --- 鍵盤顯示內容映射表 (與前次一致) --- |
347 | 346 | const letter_maps = { |
348 | 347 | 'cn_normal': (key) => key.toUpperCase(), |
349 | 348 | 'cn_shifted': (key) => key.toUpperCase(), |
|
427 | 426 | return null; |
428 | 427 | } |
429 | 428 |
|
| 429 | + /** |
| 430 | + * 核心格式化函數:將半型英文字母/符號碼轉換為全型顯示。 |
| 431 | + * 用於:輸入區 (main-input) 和 查碼結果 (search-result)。 |
| 432 | + */ |
430 | 433 | function formatCode(code) { |
431 | 434 | let displayString = ''; |
432 | 435 | const map = key_display_maps.cn_normal; |
|
435 | 438 | if (char.match(/^[a-z]$/)) { |
436 | 439 | const upperCaseChar = char.toUpperCase(); |
437 | 440 | if (upperCaseChar >= 'A' && upperCaseChar <= 'Z') { |
| 441 | + // 將 A-Z 轉為全型 A-Z (U+FF21 - U+FF3A) |
438 | 442 | const fullwidthChar = String.fromCharCode(upperCaseChar.charCodeAt(0) - 0x20 + 0xFF00); |
439 | 443 | displayString += fullwidthChar; |
440 | 444 | } else { |
441 | 445 | displayString += upperCaseChar; |
442 | 446 | } |
443 | 447 | } else if (map[char]) { |
| 448 | + // 處理 ; ' , . / 轉為全型符號 ; 〃 , . / |
444 | 449 | displayString += map[char]; |
445 | 450 | } else { |
446 | 451 | displayString += char; |
447 | 452 | } |
448 | 453 | } |
449 | 454 | return displayString; |
450 | 455 | } |
451 | | - |
452 | | - // 查碼功能專用:編碼格式化 |
453 | | - function formatCodeForSearch(code) { |
454 | | - let displayString = ''; |
455 | | - for (const char of code) { |
456 | | - displayString += char.toUpperCase(); |
457 | | - } |
458 | | - return displayString; |
459 | | - } |
460 | 456 |
|
461 | 457 | function formatComposition(code) { |
462 | 458 | if (!code) return ''; |
|
834 | 830 |
|
835 | 831 | async function loadSecondaryCodemap() { |
836 | 832 | const fileName = './3codes2.txt'; |
837 | | - let textToParse = `# 這是備用的模擬編碼表\nqwe\t測試\n`; |
| 833 | + let textToParse = `# 這是備用的模擬編碼表\nqwe\t測試\n「\t[;'\n」\t';]\n○\tqwe\n`; // 增加測試符號 |
838 | 834 | let statusMessage = '編碼表載入中...'; |
839 | 835 |
|
840 | 836 | try { |
|
1178 | 1174 | } |
1179 | 1175 | } |
1180 | 1176 |
|
1181 | | - // --- 查碼功能事件處理 --- |
| 1177 | + // --- 查碼功能事件處理 (已修復) --- |
1182 | 1178 | function handleSearchInput(event) { |
1183 | 1179 | const charToSearch = searchInput.value; |
1184 | 1180 | if (charToSearch.length === 1) { |
1185 | | - // 檢查是否為中文字 (簡單判斷) |
1186 | | - if (charToSearch.match(/[\u4e00-\u9fff]/)) { |
1187 | | - const codes = currentReverseCodemap[charToSearch]; |
1188 | | - if (codes && codes.length > 0) { |
1189 | | - const formattedCodes = codes.map(code => formatCodeForSearch(code)); |
1190 | | - searchResult.textContent = `編碼: ${formattedCodes.join(' ')}`; |
1191 | | - } else { |
1192 | | - searchResult.textContent = '找不到該漢字編碼。'; |
1193 | | - } |
| 1181 | + |
| 1182 | + // 移除字符類型檢查,直接查找碼表 |
| 1183 | + const codes = currentReverseCodemap[charToSearch]; |
| 1184 | + |
| 1185 | + if (codes && codes.length > 0) { |
| 1186 | + // 使用 formatCode 函數確保編碼以全型字元顯示 |
| 1187 | + const formattedCodes = codes.map(code => formatCode(code)); |
| 1188 | + searchResult.textContent = `編碼: ${formattedCodes.join(' ')}`; |
1194 | 1189 | } else { |
1195 | | - searchResult.textContent = '請輸入一個中文字查詢。'; |
| 1190 | + // 修正提示訊息,接受所有字符 |
| 1191 | + searchResult.textContent = '找不到該字符的編碼。'; |
1196 | 1192 | } |
1197 | 1193 | } else { |
1198 | 1194 | searchResult.textContent = '查詢結果顯示在此'; |
|
0 commit comments