NGA Character Code Converter

NGA 字符转码:发表、回复、编辑时,在提交前自动将部分原本直接提交无法正常显示的字符进行转码,使之提交后可以正常显示;编辑时将代码转回字符,方便编辑。

נכון ליום 11-03-2017. ראה הגרסה האחרונה.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         NGA Character Code Converter
// @namespace    https://greatest.deepsurf.us/zh-CN/scripts/28052-nga-character-code-converter
// @version      0.0.2
// @description  NGA 字符转码:发表、回复、编辑时,在提交前自动将部分原本直接提交无法正常显示的字符进行转码,使之提交后可以正常显示;编辑时将代码转回字符,方便编辑。
// @author       AgLandy
// @include      /^https?://(bbs\.ngacn\.cc|nga\.178\.com|bbs\.nga\.cn)/.+/
// @grant        none
// ==/UserScript==


function addScript(s){
    var newScript = document.createElement("script");
    newScript.setAttribute("type", "text/javascript");
    newScript.appendChild(document.createTextNode(s));
    document.getElementsByTagName("head")[0].appendChild(newScript);
}

function u2a(){
    var t = document.getElementsByTagName("TEXTAREA")[0].value;
    if(t){
        var r = /&#(\d+);/;
        while(r.test(t))
            t = t.replace(r, String.fromCharCode(RegExp.$1));
        document.getElementsByTagName("TEXTAREA")[0].value = t;
    }
}

function codeC(){
    if(document.getElementsByTagName("TEXTAREA").length){
        u2a();
        var sc = "function nCCC(e){\
var t = document.getElementsByTagName('TEXTAREA')[0].value;\
if(t){\
if(e.button == 2){\
var r = /&#(\\d+);/;\
while(r.test(t))\
t = t.replace(r, String.fromCharCode(RegExp.$1));\
}\
else{\
var r = /([\\u00a0-\\u02ff\\u2010-\\u2013\\u2015-\\u2017\\u2025\\u2030-\\u203e\\u2105\\u2109\\u2116\\u2121\\u2160-\\u217f\\u2190-\\u2199\\u2200-\\u22ff\\u2312\\u2460-\\u249b\\u2500-\\u2642\\u3000\\u3003-\\u3029\\u30f4-\\u30f6\\u3100-\\u312f\\u3190-\\u319f\\u3220-\\u3243\\u3280-\\u32b0\\u338e-\\u33d5\\ufe30-\\ufe6f\\uff02-\\uff0b\\uff0d-\\uff19\\uff1c-\\uff1e\\uff20-\\uff5d\\uffe2-\\uffe4])/;\
while(r.test(t))\
t = t.replace(r, '&#' + RegExp.$1.charCodeAt() + ';');\
}\
document.getElementsByTagName('TEXTAREA')[0].value = t;\
}\
}";
        addScript(sc);
        var b = document.getElementsByClassName(" uitxt1");
        b[b.length - 1].setAttribute('onmousedown','nCCC(event)');
    }
}

addEventListener ('DOMContentLoaded', codeC(), false);