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-29 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         TieqViet-ize
// @version      1.0.1
// @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       Dogekutesky's
// @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):not(span[data-text="true"])').contents().filter(function(){return (this.nodeType == 3) && this.nodeValue.match(/[a-zA-Z_ÀÁÂÃÈÉÊÌÍÒÓÔÕÙÚĂĐĨŨƠàáâãèéêìíòóôõùúăđĩũơƯĂẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼỀỀỂưăạảấầẩẫậắằẳẵặẹẻẽềềểỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪễệỉịọỏốồổỗộớờởỡợụủứừỬỮỰỲỴÝỶỸửữựỳỵỷỹ]/); }).each(function() {
        var text = tieqViet($(this).text());
        //console.log(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);