因為經常有簡體網路小說或文章需要轉換成繁體,使用OpenCC等工具覺得有點麻煩,於是便用EmEditor寫了簡單的巨集腳本,只要執行巨集就能快速的完成轉換。
這種作法的優點是能依轉換的需求自行控制,隨著轉換次數增多,就能逐日增加自己常用的詞彙,轉換也能逐漸準確。
簡轉繁巨集 範例
重點:
- 將要轉換的文字放入陣列
- 將檔案內容存入變數
_sText
,再用字串的.replace()
做替換 - 直接使用
document.selection.Replace()
效率很差,直接用變數做快速很多 - 我把一般文字和正則運算式拆成兩段來處理,其實寫成一個陣列也是可以的
// ebook
var aWords = [
["干", "幹"],
[ "乾什麼","幹什麼" ],
[ "乾涉","干涉" ],
[ "乾嘛","幹嘛" ],
[ "乾警","幹警" ],
[ "乾實事","幹實事" ],
[ "幹戈","干戈" ],
[ "乾戈","干戈" ],
[ "干嘛","幹嘛" ],
[ "干什麼","幹什麼" ],
[ "干過","幹過" ],
[ "不相乾","不相干" ],
[ "乾擾","干擾" ],
[ "干脆","乾脆" ],
[ "乾的好","幹的好" ],
[ "乾得好","幹得好" ],
[ "好好乾","好好幹" ],
[ "幹了","乾了" ],
[ "么","麼" ],
[ "麼弟","么弟" ],
[ "麼妹","么妹" ],
[ "(求訂閱!)","" ],
// .... 自行維護
];
var x = document.selection.GetActivePointX(eePosLogical);
var y = document.selection.GetActivePointY(eePosLogical);
document.selection.SelectAll();
var _sText = document.selection.Text;
for (let i = 0; i < aWords.length; i++) {
//alert(aWords[i][0] + "," + aWords[i][1]);
//document.selection.Replace(aWords[i][0],aWords[i][1],eeFindNext | eeFindSaveHistory | eeReplaceAll);
_sText = _sText.replaceAll(aWords[i][0], aWords[i][1]);
}
aWords = [
[ "干(.*)活","幹$1活" ],
[ "(.*)月票(.*)","" ],
[ "斗(.*)贏","鬥$1贏" ],
[ "^愛下電子書(.*)","" ],
[ "^『狀態:已完結』","" ],
[ "^(\\d+)\\.第(.*)","第$2" ],
[ "^『(.*)/作者:(.*)』","$1-$2" ],
[ "^(.*)謝謝(.*)打賞(.*)\n$","" ],
[ "^(.*)求票(.*)拜票(.*)\n$","" ],
[ "^(.*)拜票(.*)求票(.*)\n$","" ],
[ "^(.*)求(.*)推薦票(.*)\n$","" ],
];
for (let i = 0; i < aWords.length; i++) {
//document.selection.Replace(aWords[i][0],aWords[i][1],eeFindNext | eeReplaceAll | eeFindReplaceRegExp);
_sText = _sText.replaceAll(aWords[i][0],aWords[i][1]);
}
document.selection.Text = _sText;
editor.ExecuteCommandByID(4099); // Ctrl+S
document.selection.SetActivePoint(1, x, y, false);
//alert("Done!");
相關鏈接
##
您可能也會有興趣的類似文章
- 使用Calibre轉換TXT電子書(含目錄)並傳送至Kindle Paperwhite操作全攻略 (6則留言, 2015/01/02)
- 使用EmEditor以特定編碼開檔的方法 (0則留言, 2014/03/21)
- 自製ePub電子書技巧分享;亞馬遜Kindle的輔助工具 (0則留言, 2022/08/14)
- Obs150|多重筆記標籤操作-新增與移除:Multi Tag、TagMany、Notepad++、EmEditor、VS Code (0則留言, 2024/02/04)
- 由文字檔產生Kindle .MOBI檔的操作步驟-使用EmEditor+M2M+KindleGen+IFTTT.com (0則留言, 2019/04/15)
- Obs127|用Templater Hotkeys簡化Obsidian自動化腳本,詳解4個腳本範例 (0則留言, 2023/05/05)
- PSPad: 可以用來取代EmEditor的編輯程式 (0則留言, 2004/12/03)
- 支援Unicode的Autohotkey終於浮上抬面! (3則留言, 2010/10/16)
- 用OpenCC快速、準確的簡繁互轉 (2則留言, 2019/05/05)
- EmEditor如何新增檔案編碼? (0則留言, 2012/12/05)
- 用Ubiquity快速發佈 Plurk 訊息 (4則留言, 2008/09/26)
- 用jQuery改造WordPress網頁 (2則留言, 2009/10/27)
- 用Ubiquity快速發佈Plurk訊息-用%l替換網址 (0則留言, 2008/10/07)
- 用Ubiquity快速發佈 Plurk 訊息-改良版 (0則留言, 2008/09/27)
- HighLight:程式碼顯示的美化工具 (0則留言, 2008/10/04)