Skip to content

Instantly share code, notes, and snippets.

@yuta0801
Created October 17, 2019 09:26
Show Gist options
  • Select an option

  • Save yuta0801/6e701fb0aaa2d645ac2ecafceaf8ae42 to your computer and use it in GitHub Desktop.

Select an option

Save yuta0801/6e701fb0aaa2d645ac2ecafceaf8ae42 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Wired Normalizer
// @namespace https://github.com/bromne/wired-normalizer
// @version 1.3.0
// @description WIRED.jp の記事に含まれる「ヴ」を、適当なバ行の文字に変換します。
// @author @bromne, @yuta0801
// @match *://wired.jp/*
// @grant none
// @require //ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js
// ==/UserScript==
$(function() {
var rules = [
[/ヴェイ/g, "ベー"],
[/ヴュ/g, "ビュ"],
[/ヴァ/g, "バ"],
[/ヴィ/g, "ビ"],
[/ヴェ/g, "ベ"],
[/ヴォ/g, "ボ"],
[/ヴ/g, "ブ"],
];
var replaceCharacters = function() {
$('body :not(script,iframe)').contents().filter(function() {
return this.nodeType === 3 && this.nodeValue.match(/^[\n \t ]*$/) === null;
}).replaceWith(function() {
return rules.reduce(function(text, rule) {
return text.replace(rule[0], rule[1]);
}, this.nodeValue);
});
};
replaceCharacters();
$("#main-article-detail-container,#loaded-more-articles").each(function(i, element) {
var observer = new MutationObserver((dom, instance) => replaceCharacters());
observer.observe(element, { childList: true });
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment