LoginSignup
1
1

More than 5 years have passed since last update.

歴史的仮名遣を現代仮名遣いに変換する

Last updated at Posted at 2017-01-12

前提

macOS Sierra
Google Chrome

ScriptAutoRunner Install

ScriptAutoRunnerというJavaScriptを自動実行させる拡張機能があります。これをインストールします。

以下にくわしい使い方が記載されています。
http://qiita.com/nakajmg/items/bcbf0e5debcfa70c8d63

JavaScript追加

ScriptAutoRunner のオプションページで スクリーンショット 2017-02-25 23.07.09.png をクリックし、Script の中に以下のスクリプトをコピペします。

// ==UserScript==
// @name           WebAborn
// @version        19.20170112005808
// @namespace      http://webaborn.herokuapp.com
// @description    Reduce the situation you see disagreeable texts in the way replacing to some word.  ('aborn' means 'purge and unable to read'.)
// @include        *
// ==/UserScript
(function () {
  const abornStrings = ['い', 'い', 'え', 'う', 'とう', 'え', 'しょう', 'おう', 'こう', 'った', 'って', 'じゃ', 'そう', 'よう'];
  const ng_words = ['ゐ', 'ひ', 'へ', 'ふ', 'たう', 'ゑ', 'せう', 'はう', 'かう', 'つた', 'つて', 'ぢや', 'さう', 'やう'];
  var webaborn = function(node){
    var candidates = document.evaluate('.//text()[not(parent::style) and not(parent::textarea) and not(parent::script)]', node, null, 6, null);
    var i, j, lenC, lenNG, txt;
    for (i=0, lenC=candidates.snapshotLength; i<lenC; i++) {
      txt = candidates.snapshotItem(i).nodeValue;
      for (j=0, lenNG=ng_words.length; j<lenNG; j++){
        if(txt.indexOf(ng_words[j]) >= 0){
          candidates.snapshotItem(i).nodeValue = candidates.snapshotItem(i).nodeValue.replace(new RegExp(ng_words[j],"g"), abornStrings[j]);
        }
      }
    }
    candidates = document.evaluate('.//input[not(@type="text")]/@value | .//img/@alt | .//*/@title | .//a/@href', node, null, 6, null);
    for (i=0, lenC=candidates.snapshotLength; i<lenC; i++) {
      txt = candidates.snapshotItem(i).value;
      for (j=0; j<lenNG; j++){
        if(txt.indexOf(ng_words[j]) >= 0){
          candidates.snapshotItem(i).value = candidates.snapshotItem(i).value.replace(new RegExp(ng_words[j],"g"), abornStrings[j]);
        }
      }
    }
  };

  var nodeText = document.evaluate('//text()', document, null, 6, null);
  var nodePre = document.evaluate('//pre', document, null, 6, null);
  if (nodeText.snapshotLength===1 && nodePre.snapshotLength===1){
    var del = nodeText.snapshotItem(0);
    var lines = del.nodeValue.split(/\r?\n/);
    var ins = document.createElement('pre');
    ins.style.whiteSpace = 'pre-wrap';
    del.parentNode.replaceChild(ins, del);
    var i, len;
    for(i=0, len=lines.length; i<len; i++){
      ins.appendChild(document.createTextNode(lines[i]));
      ins.appendChild(document.createElement('br'));
    }
  }

  webaborn(document);
  document.addEventListener('DOMNodeInserted', function(e){ webaborn(e.target); }, false);
  document.addEventListener('DOMCharacterDataModified', function(e){ webaborn(e.target); }, false);
  document.addEventListener('DOMAttrModified', function(e){ webaborn(e.target); }, false);
})();

aa981448-6637-9cad-f5be-3b1777b9b1d5.png

有効化

コンセント部分と壁部分をクリックします。
黄色で通電するような感じになったら有効化できてます。

a5420b8d-e440-86c6-2beb-dd8d0585baf1.gif

動作確認

歴史的仮名遣のあるページを開いたり再読込すると文字が変換されると思います。


以上です。

1
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1