Skip to content

Instantly share code, notes, and snippets.

@MakotoE
Created June 19, 2018 19:50
Show Gist options
  • Save MakotoE/28c6493ea47a1dcfd7371f570778b711 to your computer and use it in GitHub Desktop.
Save MakotoE/28c6493ea47a1dcfd7371f570778b711 to your computer and use it in GitHub Desktop.
// Applies CJK conversion to specified documents.
//All characters except for '礼(FA18), 恵(FA6B), 𤋮(FA6C), 舘(FA6D), 𢡊(FBCF), 𢡄(FBD0), 𣏕(FBD1), 𥉉(FBD5), 𥳐(FBD6), 𧻓(FBD7)' are changed into CJK unified characters
//礼(FA18), 恵(FA6B), 𤋮(FA6C), 舘(FA6D) are changed popular normal characters. 𢡊(FBCF), 𢡄(FBD0), 𣏕(FBD1), 𥉉(FBD5), 𥳐(FBD6), 𧻓(FBD7) are omitted, because they correspond to SMP characters.
// Document path
var folderPath = "C:\\Users\\makot\\Downloads\\"; // Use double backslash to use backslash character in string
// List of documents to process
var docs = [
["test1.txt"],
["test2.txt"]
];
// List of [original character, converted character] pairs
var characterConversions = [
["\uf900","\u8c48"], // Unicode characters can be written like this
["更","更"],
["車","車"],
["賈","賈"],
["滑","滑"],
["串","串"],
["句","句"],
["龜","龜"],
["龜","龜"],
["契","契"],
["金","金"],
["喇","喇"],
["奈","奈"],
["懶","懶"],
["癩","癩"],
["羅","羅"],
["蘿","蘿"],
["螺","螺"],
["裸","裸"],
["邏","邏"],
["樂","樂"],
["洛","洛"],
["烙","烙"],
["珞","珞"],
["落","落"],
["酪","酪"],
["駱","駱"],
["亂","亂"],
["卵","卵"],
["欄","欄"],
["爛","爛"],
["蘭","蘭"],
["鸞","鸞"],
["嵐","嵐"],
["濫","濫"],
["藍","藍"],
["襤","襤"],
["拉","拉"],
["臘","臘"],
["蠟","蠟"],
["廊","廊"],
["朗","朗"],
["浪","浪"],
["狼","狼"],
["郎","郞"],
["來","來"],
["冷","冷"],
["勞","勞"],
["擄","擄"],
["櫓","櫓"],
["爐","爐"],
["盧","盧"],
["老","老"],
["蘆","蘆"],
["虜","虜"],
["路","路"],
["露","露"],
["魯","魯"],
["鷺","鷺"],
["碌","碌"],
["祿","祿"],
["綠","綠"],
["菉","菉"],
["錄","錄"],
["鹿","鹿"],
["論","論"],
["壟","壟"],
["弄","弄"],
["籠","籠"],
["聾","聾"],
["牢","牢"],
["磊","磊"],
["賂","賂"],
["雷","雷"],
["壘","壘"],
["屢","屢"],
["樓","樓"],
["淚","淚"],
["漏","漏"],
["累","累"],
["縷","縷"],
["陋","陋"],
["勒","勒"],
["肋","肋"],
["凜","凜"],
["凌","凌"],
["稜","稜"],
["綾","綾"],
["菱","菱"],
["陵","陵"],
["讀","讀"],
["拏","拏"],
["樂","樂"],
["諾","諾"],
["丹","丹"],
["寧","寧"],
["怒","怒"],
["率","率"],
["異","異"],
["北","北"],
["磻","磻"],
["便","便"],
["復","復"],
["不","不"],
["泌","泌"],
["數","數"],
["索","索"],
["參","參"],
["塞","塞"],
["省","省"],
["葉","葉"],
["說","說"],
["殺","殺"],
["辰","辰"],
["沈","沈"],
["拾","拾"],
["若","若"],
["掠","掠"],
["略","略"],
["亮","亮"],
["兩","兩"],
["凉","凉"],
["梁","梁"],
["糧","糧"],
["良","良"],
["諒","諒"],
["量","量"],
["勵","勵"],
["呂","呂"],
["女","女"],
["廬","廬"],
["旅","旅"],
["濾","濾"],
["礪","礪"],
["閭","閭"],
["驪","驪"],
["麗","麗"],
["黎","黎"],
["力","力"],
["曆","曆"],
["歷","歷"],
["轢","轢"],
["年","年"],
["憐","憐"],
["戀","戀"],
["撚","撚"],
["漣","漣"],
["煉","煉"],
["璉","璉"],
["秊","秊"],
["練","練"],
["聯","聯"],
["輦","輦"],
["蓮","蓮"],
["連","連"],
["鍊","鍊"],
["列","列"],
["劣","劣"],
["咽","咽"],
["烈","烈"],
["裂","裂"],
["說","說"],
["廉","廉"],
["念","念"],
["捻","捻"],
["殮","殮"],
["簾","簾"],
["獵","獵"],
["令","令"],
["囹","囹"],
["寧","寧"],
["嶺","嶺"],
["怜","怜"],
["玲","玲"],
["瑩","瑩"],
["羚","羚"],
["聆","聆"],
["鈴","鈴"],
["零","零"],
["靈","靈"],
["領","領"],
["例","例"],
["禮","禮"],
["醴","醴"],
["隸","隷"],
["惡","惡"],
["了","了"],
["僚","僚"],
["寮","寮"],
["尿","尿"],
["料","料"],
["樂","樂"],
["燎","燎"],
["療","療"],
["蓼","蓼"],
["遼","遼"],
["龍","龍"],
["暈","暈"],
["阮","阮"],
["劉","劉"],
["杻","杻"],
["柳","柳"],
["流","流"],
["溜","溜"],
["琉","琉"],
["留","留"],
["硫","硫"],
["紐","紐"],
["類","類"],
["六","六"],
["戮","戮"],
["陸","陸"],
["倫","倫"],
["崙","崙"],
["淪","淪"],
["輪","輪"],
["律","律"],
["慄","慄"],
["栗","栗"],
["率","率"],
["隆","隆"],
["利","利"],
["吏","吏"],
["履","履"],
["易","易"],
["李","李"],
["梨","梨"],
["泥","泥"],
["理","理"],
["痢","痢"],
["罹","罹"],
["裏","裏"],
["裡","裡"],
["里","里"],
["離","離"],
["匿","匿"],
["溺","溺"],
["吝","吝"],
["燐","燐"],
["璘","璘"],
["藺","藺"],
["隣","隣"],
["鱗","鱗"],
["麟","麟"],
["林","林"],
["淋","淋"],
["臨","臨"],
["立","立"],
["笠","笠"],
["粒","粒"],
["狀","狀"],
["炙","炙"],
["識","識"],
["什","什"],
["茶","茶"],
["刺","刺"],
["切","切"],
["度","度"],
["拓","拓"],
["糖","糖"],
["宅","宅"],
["洞","洞"],
["暴","暴"],
["輻","輻"],
["行","行"],
["降","降"],
["見","見"],
["廓","廓"],
["兀","兀"],
["嗀","嗀"],
["﨎","﨎"],
["﨏","﨏"],
["塚","塚"],
["﨑","﨑"],
["晴","晴"],
["﨓","﨓"],
["﨔","﨔"],
["凞","凞"],
["猪","猪"],
["益","益"],
["礼","禮"],
["神","神"],
["祥","祥"],
["福","福"],
["靖","靖"],
["精","精"],
["羽","羽"],
["﨟","﨟"],
["蘒","蘒"],
["﨡","﨡"],
["諸","諸"],
["﨣","﨣"],
["﨤","﨤"],
["逸","逸"],
["都","都"],
["﨧","﨧"],
["﨨","﨨"],
["﨩","﨩"],
["飯","飯"],
["飼","飼"],
["館","館"],
["鶴","鶴"],
["郞","郞"],
["隷","隷"],
["侮","侮"],
["僧","僧"],
["免","免"],
["勉","勉"],
["勤","勤"],
["卑","卑"],
["喝","喝"],
["嘆","嘆"],
["器","器"],
["塀","塀"],
["墨","墨"],
["層","層"],
["屮","屮"],
["悔","悔"],
["慨","慨"],
["憎","憎"],
["懲","懲"],
["敏","敏"],
["既","既"],
["暑","暑"],
["梅","梅"],
["海","海"],
["渚","渚"],
["漢","漢"],
["煮","煮"],
["爫","爫"],
["琢","琢"],
["碑","碑"],
["社","社"],
["祉","祉"],
["祈","祈"],
["祐","祐"],
["祖","祖"],
["祝","祝"],
["禍","禍"],
["禎","禎"],
["穀","穀"],
["突","突"],
["節","節"],
["練","練"],
["縉","縉"],
["繁","繁"],
["署","署"],
["者","者"],
["臭","臭"],
["艹","艹"],
["艹","艹"],
["著","著"],
["褐","褐"],
["視","視"],
["謁","謁"],
["謹","謹"],
["賓","賓"],
["贈","贈"],
["辶","辶"],
["逸","逸"],
["難","難"],
["響","響"],
["頻","頻"],
["恵","惠"],
["𤋮","熙"],
["舘","館"],
["並","並"],
["况","况"],
["全","全"],
["侀","侀"],
["充","充"],
["冀","冀"],
["勇","勇"],
["勺","勺"],
["喝","喝"],
["啕","啕"],
["喙","喙"],
["嗢","嗢"],
["塚","塚"],
["墳","墳"],
["奄","奄"],
["奔","奔"],
["婢","婢"],
["嬨","嬨"],
["廒","廒"],
["廙","廙"],
["彩","彩"],
["徭","徭"],
["惘","惘"],
["慎","慎"],
["愈","愈"],
["憎","憎"],
["慠","慠"],
["懲","懲"],
["戴","戴"],
["揄","揄"],
["搜","搜"],
["摒","摒"],
["敖","敖"],
["晴","晴"],
["朗","朗"],
["望","望"],
["杖","杖"],
["歹","歹"],
["殺","殺"],
["流","流"],
["滛","滛"],
["滋","滋"],
["漢","漢"],
["瀞","瀞"],
["煮","煮"],
["瞧","瞧"],
["爵","爵"],
["犯","犯"],
["猪","猪"],
["瑱","瑱"],
["甆","甆"],
["画","画"],
["瘝","瘝"],
["瘟","瘟"],
["益","益"],
["盛","盛"],
["直","直"],
["睊","睊"],
["着","着"],
["磌","磌"],
["窱","窱"],
["節","節"],
["类","类"],
["絛","絛"],
["練","練"],
["缾","缾"],
["者","者"],
["荒","荒"],
["華","華"],
["蝹","蝹"],
["襁","襁"],
["覆","覆"],
["視","視"],
["調","調"],
["諸","諸"],
["請","請"],
["謁","謁"],
["諾","諾"],
["諭","諭"],
["謹","謹"],
["變","變"],
["贈","贈"],
["輸","輸"],
["遲","遲"],
["醙","醙"],
["鉶","鉶"],
["陼","陼"],
["難","難"],
["靖","靖"],
["韛","韛"],
["響","響"],
["頋","頋"],
["頻","頻"],
["鬒","鬒"],
["龜","龜"],
["㮝","㮝"],
["䀘","䀘"],
["䀹","䀹"],
["𥉉","𥉉"],
["龎","龎"]
];
// loop thhrough every document
for (var docI = 0; docI < docs.length; ++docI) {
editor.OpenFile( folderPath + docs[docI] );
// loop through every conversion pair
for (var i = 0; i < characterConversions.length; ++i) { // i is the index of characterConversions
var findReplace = characterConversions[i]; // findReplace contains the character to find and to replace with
document.selection.Replace(findReplace[0], findReplace[1], eeReplaceAll|eeFindReplaceQuiet, 0);
}
document.Save(docs[docI]); // Leave arguments blank to specify name for each document
document.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment