TieqViet-ize

Script này sẽ biến mọi trang web của bạn thành Tiếng Việt sau cải cách :)

目前为 2017-11-28 提交的版本。查看 最新版本

// ==UserScript==
// @name         TieqViet-ize
// @version      1.0
// @description   Script này sẽ biến mọi trang web của bạn thành Tiếng Việt sau cải cách :)
// @author       You
// @match        *://*/*
// @run-at       document-end
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @grant        none
// @namespace https://greasyfork.org/users/123835
// ==/UserScript==

var _typeof='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&'function'==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?'symbol':typeof a},maps=[['k(h|H)','x'],['K(h|H)','X'],['c(?!(h|H))|q','k'],['C(?!(h|H))|Q','K'],['t(r|R)|c(h|H)','c'],['T(r|R)|C(h|H)','C'],['d|g(i|I)|r','z'],['D|G(i|I)|R','Z'],['g(i|\xEC|\xED|\u1EC9|\u0129|\u1ECB|I|\xCC|\xCD|\u1EC8|\u0128|\u1ECA)','z$1'],['G(i|\xEC|\xED|\u1EC9|\u0129|\u1ECB|I|\xCC|\xCD|\u1EC8|\u0128|\u1ECA)','Z$1'],['\u0111','d'],['\u0110','D'],['p(h|H)','f'],['P(h|H)','F'],['n(g|G)(h|H)?','q'],['N(g|G)(h|H)?','Q'],['(g|G)(h|H)','$1'],['t(h|H)','w'],['T(h|H)','W'],['(n|N)(h|H)','$1\'']];var tieqViet=function(a){if('string'!=typeof a)throw new TypeError('Expected a string, got '+('undefined'==typeof a?'undefined':_typeof(a)));return maps.reduce(function(b,c){return a=a.replace(new RegExp(c[0],'g'),c[1]),a},a)}
//minified modified version of https://github.com/phanan/tieqviet/blob/master/dist/tieqviet.min.js

function modifyV(f){
    $(f).find('*:not(iframe):not(style)').contents().filter(function(){return (this.nodeType == 3) && this.nodeValue.match(/\S/); }).each(function() {
        var text = tieqViet($(this).text());
        this.nodeValue=text;
    });
}

modifyV('body');

var observer = new MutationObserver(function(mutations) {
    $(mutations).each(
        function(){
            modifyV($(this.target));
            //console.log($(this.target));
        });
});

var config = {  childList: true, subtree: true };

observer.observe(document.body,config);