Skip to content

Commit edba8c1

Browse files
committed
Update Switch Traditional Chinese and Simplified Chinese.user.js
1 parent 9c7dca8 commit edba8c1

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

Switch Traditional Chinese and Simplified Chinese/Switch Traditional Chinese and Simplified Chinese.user.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// @namespace hoothin
77
// @supportURL https://github.com/hoothin/UserScripts
88
// @homepageURL https://github.com/hoothin/UserScripts
9-
// @version 1.2.7.9
9+
// @version 1.2.7.10
1010
// @description 任意轉換網頁中的簡體中文與正體中文(默認簡體→正體),顯示漢字對應漢語拼音,自訂任意替換文本
1111
// @description:zh-CN 任意转换网页中的简体中文与繁体中文(默认繁体→简体),显示汉字对应汉语拼音,自定义任意替换文本
1212
// @description:ja ウェブページ上の簡体字中国語と繁体字中国語を自由に変換し、中国語の文字にひらがなを表示し、任意の文字を置き換えることができます。
@@ -1713,12 +1713,16 @@
17131713
storage.setItem('sc2tcCombConfig', sc2tcCombConfig);
17141714
} catch (e) {
17151715
console.log(e);
1716+
alert("自訂簡繁用語轉換格式錯誤:" + e);
1717+
return;
17161718
}
17171719
try {
17181720
illiteracyConfig = customIlliteracyInput.value ? JSON.parse(customIlliteracyInput.value) : "";
17191721
storage.setItem('illiteracyConfig', illiteracyConfig);
17201722
} catch (e) {
17211723
console.log(e);
1724+
alert("通用字詞轉換格式錯誤:" + e);
1725+
return;
17221726
}
17231727
storage.setItem('sc2tcCombTree', "");
17241728
storage.setItem('tc2scCombTree', "");
@@ -1888,32 +1892,38 @@
18881892
function makeCombTree(key, value) {
18891893
let curTree=sc2tcCombTree;
18901894
for(let i=0;i<key.length;i++){
1895+
let curKey=key.charAt(i);
1896+
let branch=curTree[curKey];
18911897
let newTree={};
18921898
if(i==key.length-1){
18931899
newTree={"end":value};
1900+
if(branch){
1901+
branch.end=value;
1902+
}
18941903
}
1895-
let curKey=key.charAt(i);
1896-
let branch=curTree[curKey];
1897-
if(!branch){
1904+
if(branch){
1905+
curTree=branch;
1906+
}else{
18981907
curTree[curKey]=newTree;
18991908
curTree=newTree;
1900-
}else{
1901-
curTree=branch;
19021909
}
19031910
}
19041911
curTree=tc2scCombTree;
19051912
for(let i=0;i<value.length;i++){
1913+
let curKey=value.charAt(i);
1914+
let branch=curTree[curKey];
19061915
let newTree={};
19071916
if(i==value.length-1){
19081917
newTree={"end":key};
1918+
if(branch){
1919+
branch.end=value;
1920+
}
19091921
}
1910-
let curKey=value.charAt(i);
1911-
let branch=curTree[curKey];
1912-
if(!branch){
1922+
if(branch){
1923+
curTree=branch;
1924+
}else{
19131925
curTree[curKey]=newTree;
19141926
curTree=newTree;
1915-
}else{
1916-
curTree=branch;
19171927
}
19181928
}
19191929
}

0 commit comments

Comments
 (0)