Skip to content

Commit 7dfb7fe

Browse files
authored
Add files via upload
1 parent 5935499 commit 7dfb7fe

1 file changed

Lines changed: 39 additions & 62 deletions

File tree

3code_mobile.html

Lines changed: 39 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -488,42 +488,10 @@
488488
const KEYCODE_DOWN=0xff54;
489489
const KEYCODE_DEL_F=0xff;
490490

491-
// --- 簡繁轉換表 (將從 ts.txt 外部檔案載入) ---
492-
let TS_MAP = {}; // 變更:改為 let 並初始化為空物件
493-
494-
// 硬編碼的備用轉換表,用於外部檔案載入失敗時
495-
const FALLBACK_TS_MAP_RAW = `
496-
# 備用簡繁轉換表 (硬編碼)
497-
體 体
498-
碼 码
499-
說 说
500-
這 这
501-
個 个
502-
們 们
503-
樂 乐
504-
風 风
505-
開 开
506-
對 对
507-
會 会
508-
國 国
509-
議 议
510-
變 变
511-
應 应
512-
學 学
513-
發 发
514-
廠 厂
515-
廣 广
516-
裡 里
517-
幾 几
518-
為 为
519-
從 从
520-
後 后
521-
麵 面
522-
術 术
523-
隻 只
524-
頭 头
525-
話 话
526-
`;
491+
// --- 簡繁轉換表 (將從 ts.txt 外部檔案載入,若失敗則為空) ---
492+
let TS_MAP = {};
493+
494+
// 移除 FALLBACK_TS_MAP_RAW,完全依賴外部檔案載入。
527495

528496
/**
529497
* 執行簡體字轉換
@@ -784,8 +752,6 @@
784752
}
785753
}
786754

787-
// --- ADDED: 浮層處理函數 (略,與前版相同) ---
788-
789755
/**
790756
* 處理表情符號/編輯器的浮層顯示與隱藏
791757
*/
@@ -920,13 +886,17 @@
920886
overlay("editor", 0);
921887
}
922888

923-
// --- REMOVED: startVoiceInput function ---
924-
925889
// --- ADDED: 工具列邏輯 ---
926890

927891
function showToolbar() {
928892
candidateDisplay.innerHTML = '';
929893

894+
// 1. 如果浮層開啟 (Emoji/Editor)
895+
if (overlayDiv.dataset.show) {
896+
showToolbar();
897+
return;
898+
}
899+
930900
// **CHANGE: Replaced '🎤' with '簡/繁' toggle**
931901
const toolbarItems = [
932902
{title: isSimplifiedMode ? "简" : "繁", tool:"1"}, // 簡繁切換鍵
@@ -957,6 +927,9 @@
957927
isSimplifiedMode = !isSimplifiedMode;
958928
showCandidates(); // Redraw toolbar to update "簡" / "繁" label
959929
console.log("Mode switched to:", isSimplifiedMode ? "Simplified" : "Traditional");
930+
if (Object.keys(TS_MAP).length === 0 && isSimplifiedMode) {
931+
alert("警告:簡繁轉換表 (ts.txt) 尚未載入或內容為空,轉換功能將不會生效。");
932+
}
960933
} else if (tool === "2") {
961934
overlay("emoji", 0);
962935
} else if (tool === "3") {
@@ -1338,42 +1311,46 @@
13381311
*/
13391312
async function loadTSMap() {
13401313
const fileName = './ts.txt';
1341-
let textToParse = FALLBACK_TS_MAP_RAW;
1314+
let textToParse = ''; // 預設為空,如果載入失敗則保持為空
13421315

13431316
try {
13441317
const response = await fetch(fileName);
13451318
if (response.ok) {
13461319
const responseText = await response.text();
1347-
// 檢查檔案內容是否有效,如果只有空白或註解,則使用備用內容
1320+
// 檢查檔案內容是否有效,如果只有空白或註解,則不使用該內容
13481321
if (responseText.trim().replace(/^#.*$/gm, '').trim().length > 0) {
13491322
textToParse = responseText;
1323+
console.log(`成功載入簡繁轉換表: ${fileName}`);
1324+
} else {
1325+
console.warn(`載入外部簡繁轉換表: ${fileName} 成功,但內容為空或僅包含註解。`);
13501326
}
1351-
console.log(`成功載入簡繁轉換表: ${fileName}`);
13521327
} else {
1353-
console.warn(`無法載入外部簡繁轉換表 (${response.status}),使用備用內容。`);
1328+
console.error(`無法載入外部簡繁轉換表 (${response.status}),TS_MAP 將保持為空。`);
13541329
}
13551330
} catch (error) {
1356-
console.error('外部簡繁轉換表讀取錯誤:', error.message, '已切換至備用內容。');
1331+
console.error('外部簡繁轉換表讀取錯誤:', error.message, 'TS_MAP 將保持為空。');
13571332
}
13581333

1359-
// 解析內容 (與 parseCinData 類似的邏輯)
1334+
// 解析內容
13601335
const newTSMap = {};
1361-
const lines = textToParse.trim().split('\n');
1362-
lines.forEach(line => {
1363-
// 忽略註解行
1364-
if (line.startsWith('#') || line.trim() === '') return;
1365-
1366-
// 使用 Tab 或多個空格分隔
1367-
const parts = line.split(/[\t\s]+/);
1368-
1369-
if (parts.length >= 2) {
1370-
const traditionalChar = parts[0].trim();
1371-
const simplifiedChar = parts[1].trim();
1372-
if (traditionalChar.length === 1 && simplifiedChar.length === 1) {
1373-
newTSMap[traditionalChar] = simplifiedChar;
1336+
if (textToParse.length > 0) {
1337+
const lines = textToParse.trim().split('\n');
1338+
lines.forEach(line => {
1339+
// 忽略註解行
1340+
if (line.startsWith('#') || line.trim() === '') return;
1341+
1342+
// 使用 Tab 或多個空格分隔
1343+
const parts = line.split(/[\t\s]+/);
1344+
1345+
if (parts.length >= 2) {
1346+
const traditionalChar = parts[0].trim();
1347+
const simplifiedChar = parts[1].trim();
1348+
if (traditionalChar.length === 1 && simplifiedChar.length === 1) {
1349+
newTSMap[traditionalChar] = simplifiedChar;
1350+
}
13741351
}
1375-
}
1376-
});
1352+
});
1353+
}
13771354

13781355
TS_MAP = newTSMap;
13791356
console.log(`簡繁轉換表已載入,共 ${Object.keys(TS_MAP).length} 條轉換規則。`);
@@ -1703,7 +1680,7 @@
17031680
// 頁面啟動
17041681
document.addEventListener('DOMContentLoaded', () => {
17051682
drawKeyboard();
1706-
loadTSMap(); // **新增:載入簡繁轉換表**
1683+
loadTSMap(); // **重要:完全依賴外部檔案載入**
17071684
loadSecondaryCodemap();
17081685

17091686
textOutput.addEventListener('click', handleTextTap);

0 commit comments

Comments
 (0)