Quantcast
Channel: 簡睿隨筆
Viewing all articles
Browse latest Browse all 897

EmEditor 快速簡轉繁巨集

$
0
0

因為經常有簡體網路小說或文章需要轉換成繁體,使用OpenCC等工具覺得有點麻煩,於是便用EmEditor寫了簡單的巨集腳本,只要執行巨集就能快速的完成轉換。

這種作法的優點是能依轉換的需求自行控制,隨著轉換次數增多,就能逐日增加自己常用的詞彙,轉換也能逐漸準確。

簡轉繁巨集 範例

重點:

  1. 將要轉換的文字放入陣列
  2. 將檔案內容存入變數 _sText,再用字串的.replace()做替換
  3. 直接使用document.selection.Replace()效率很差,直接用變數做快速很多
  4. 我把一般文字和正則運算式拆成兩段來處理,其實寫成一個陣列也是可以的
// 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!");

相關鏈接

##

您可能也會有興趣的類似文章


Viewing all articles
Browse latest Browse all 897

Trending Articles