前提
macOS Sierra
Google Chrome
ScriptAutoRunner Install
ScriptAutoRunnerというJavaScriptを自動実行させる拡張機能があります。これをインストールします。
以下にくわしい使い方が記載されています。
http://qiita.com/nakajmg/items/bcbf0e5debcfa70c8d63
JavaScript追加
ScriptAutoRunner のオプションページで をクリックし、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);
})();
有効化
コンセント部分と壁部分をクリックします。
黄色で通電するような感じになったら有効化できてます。
動作確認
歴史的仮名遣のあるページを開いたり再読込すると文字が変換されると思います。
以上です。