Benissou / JVC Unicode

// ==UserScript==
// @name        JVC Unicode
// @author       Benissou
// @description  Convertissez votre texte en unicode
// @include      http://www.jeuxvideo.com/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @version      0.9
// @icon         http://image.noelshack.com/fichiers/2016/50/1481684643-benissou.gif 
// @copyright    2016+, Benissou
// ==/UserScript==


/*jshint multistr: true */

var alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0','1', '2', '3', '4', '5', '6', '7', '8', '9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];

var regional = ['๐Ÿ‡ฆ','๐Ÿ‡ง','๐Ÿ‡จ','๐Ÿ‡ฉ','๐Ÿ‡ช','๐Ÿ‡ซ','๐Ÿ‡ฌ','๐Ÿ‡ญ','๐Ÿ‡ฎ','๐Ÿ‡ฏ','๐Ÿ‡ฐ','๐Ÿ‡ฑ','๐Ÿ‡ฒ','๐Ÿ‡ณ','๐Ÿ‡ด','๐Ÿ‡ต','๐Ÿ‡ถ','๐Ÿ‡ท','๐Ÿ‡ธ','๐Ÿ‡น','๐Ÿ‡บ','๐Ÿ‡ป','๐Ÿ‡ผ','๐Ÿ‡ฝ','๐Ÿ‡พ','๐Ÿ‡ฟ','0','1', '2', '3', '4', '5', '6', '7', '8', '9','๐Ÿ‡ฆ','๐Ÿ‡ง','๐Ÿ‡จ','๐Ÿ‡ฉ','๐Ÿ‡ช','๐Ÿ‡ซ','๐Ÿ‡ฌ','๐Ÿ‡ญ','๐Ÿ‡ฎ','๐Ÿ‡ฏ','๐Ÿ‡ฐ','๐Ÿ‡ฑ','๐Ÿ‡ฒ','๐Ÿ‡ณ','๐Ÿ‡ด','๐Ÿ‡ต','๐Ÿ‡ถ','๐Ÿ‡ท','๐Ÿ‡ธ','๐Ÿ‡น','๐Ÿ‡บ','๐Ÿ‡ป','๐Ÿ‡ผ','๐Ÿ‡ฝ','๐Ÿ‡พ','๐Ÿ‡ฟ'];
var Fullwidth = ['๏ฝ','๏ฝ‚','๏ฝƒ','๏ฝ„','๏ฝ…','๏ฝ†','๏ฝ‡','๏ฝˆ','๏ฝ‰','๏ฝŠ','๏ฝ‹','๏ฝŒ','๏ฝ','๏ฝŽ','๏ฝ','๏ฝ','๏ฝ‘','๏ฝ’','๏ฝ“','๏ฝ”','๏ฝ•','๏ฝ–','๏ฝ—','๏ฝ˜','๏ฝ™','๏ฝš','๏ผ','๏ผ‘','๏ผ’','๏ผ“','๏ผ”','๏ผ•','๏ผ–','๏ผ—','๏ผ˜','๏ผ™','๏ผก','๏ผข','๏ผฃ','๏ผค','๏ผฅ','๏ผฆ','๏ผง','๏ผจ','๏ผฉ','๏ผช','๏ผซ','๏ผฌ','๏ผญ','๏ผฎ','๏ผฏ','๏ผฐ','๏ผฑ','๏ผฒ','๏ผณ','๏ผด','๏ผต','๏ผถ','๏ผท','๏ผธ','๏ผน','๏ผบ'];
var Mathdouble = ['๐•’','๐•“','๐•”','๐••','๐•–','๐•—','๐•˜','๐•™','๐•š','๐•›','๐•œ','๐•','๐•ž','๐•Ÿ','๐• ','๐•ก','๐•ข','๐•ฃ','๐•ค','๐•ฅ','๐•ฆ','๐•ง','๐•จ','๐•ฉ','๐•ช','๐•ซ','๐Ÿ˜','๐Ÿ™','๐Ÿš','๐Ÿ›','๐Ÿœ','๐Ÿ','๐Ÿž','๐ŸŸ','๐Ÿ ','๐Ÿก','๐”ธ','๐”น','โ„‚','๐”ป','๐”ผ','๐”ฝ','๐”พ','โ„','๐•€','๐•','๐•‚','๐•ƒ','๐•„','โ„•','๐•†','โ„™','โ„š','โ„','๐•Š','๐•‹','๐•Œ','๐•','๐•Ž','๐•','๐•','โ„ค'];
var Circled = ['๐Ÿ…','๐Ÿ…‘','๐Ÿ…’','๐Ÿ…“','๐Ÿ…”','๐Ÿ…•','๐Ÿ…–','๐Ÿ…—','๐Ÿ…˜','๐Ÿ…™','๐Ÿ…š','๐Ÿ…›','๐Ÿ…œ','๐Ÿ…','๐Ÿ…ž','๐Ÿ…Ÿ','๐Ÿ… ','๐Ÿ…ก','๐Ÿ…ข','๐Ÿ…ฃ','๐Ÿ…ค','๐Ÿ…ฅ','๐Ÿ…ฆ','๐Ÿ…ง','๐Ÿ…จ','๐Ÿ…ฉ','โ“ฟ','0','1', '2', '3', '4', '5', '6', '7', '8', '9','๐Ÿ…','๐Ÿ…‘','๐Ÿ…’','๐Ÿ…“','๐Ÿ…”','๐Ÿ…•','๐Ÿ…–','๐Ÿ…—','๐Ÿ…˜','๐Ÿ…™','๐Ÿ…š','๐Ÿ…›','๐Ÿ…œ','๐Ÿ…','๐Ÿ…ž','๐Ÿ…Ÿ','๐Ÿ… ','๐Ÿ…ก','๐Ÿ…ข','๐Ÿ…ฃ','๐Ÿ…ค','๐Ÿ…ฅ','๐Ÿ…ฆ','๐Ÿ…ง','๐Ÿ…จ','๐Ÿ…ฉ','โ“ฟ'];
var Squared = ['๐Ÿ…ฐ','๐Ÿ…ฑ','๐Ÿ…ฒ','๐Ÿ…ณ','๐Ÿ…ด','๐Ÿ…ต','๐Ÿ…ถ','๐Ÿ…ท','๐Ÿ…ธ','๐Ÿ…น','๐Ÿ…บ','๐Ÿ…ป','๐Ÿ…ผ','๐Ÿ…ฝ','๐Ÿ…พ','๐Ÿ…ฟ','๐Ÿ†€','๐Ÿ†','๐Ÿ†‚','๐Ÿ†ƒ','๐Ÿ†„','๐Ÿ†…','๐Ÿ††','๐Ÿ†‡','๐Ÿ†ˆ','๐Ÿ†‰','0','1', '2', '3', '4', '5', '6', '7', '8', '9','๐Ÿ…ฐ','๐Ÿ…ฑ','๐Ÿ…ฒ','๐Ÿ…ณ','๐Ÿ…ด','๐Ÿ…ต','๐Ÿ…ถ','๐Ÿ…ท','๐Ÿ…ธ','๐Ÿ…น','๐Ÿ…บ','๐Ÿ…ป','๐Ÿ…ผ','๐Ÿ…ฝ','๐Ÿ…พ','๐Ÿ…ฟ','๐Ÿ†€','๐Ÿ†','๐Ÿ†‚','๐Ÿ†ƒ','๐Ÿ†„','๐Ÿ†…','๐Ÿ††','๐Ÿ†‡','๐Ÿ†ˆ','๐Ÿ†‰'];

(function() {
	
    'use strict';
	
	$('.jv-editor-toolbar').append('<div id="unicode" ></div>');	
	$('#unicode').append('<div class="btn-group">\
	<button class="btn btn-jv-editor-toolbar" id="char_regional" type="button" title=""><span>๐Ÿ‡ฆ</span></button>\
	<button class="btn btn-jv-editor-toolbar" id="char_Fullwidth" type="button" title=""><span>๏ฝ</span></button>\
	<button class="btn btn-jv-editor-toolbar" id="char_Mathdouble" type="button" title=""><span>๐•’</span></button>\
	<button class="btn btn-jv-editor-toolbar" id="char_Circled" type="button" title=""><span>๐Ÿ…</span></button>\
	<button class="btn btn-jv-editor-toolbar" id="char_Squared" type="button" title=""><span>๐Ÿ…ฐ</span></button>\
	</div>');
	document.getElementById('char_regional').addEventListener('click', function() {char_unicode(regional);});
	document.getElementById('char_Fullwidth').addEventListener('click', function() {char_unicode(Fullwidth);});
	document.getElementById('char_Mathdouble').addEventListener('click', function() {char_unicode(Mathdouble);});
	document.getElementById('char_Circled').addEventListener('click', function() {char_unicode(Circled);});	
	document.getElementById('char_Squared').addEventListener('click', function() {char_unicode(Squared);});	
	function char_unicode (table)
	{
		var elem = document.getElementById('message_topic');
		var start = elem.selectionStart;
		var end = elem.selectionEnd;
		var len = elem.value.length;
		var sel_txt = elem.value.substring(start,end);
		elem.value = elem.value.substring(0,start) + encodeunicode(sel_txt, table)+ elem.value.substring(end,len);
	}
	
function cleanUpSpecialChars(str)
{
    str = str.replace(/[ร รกรขรฃรครฅ]/g,"a");
    str = str.replace(/[ร€รร‚รƒร„ร…]/g,"A");
	str = str.replace(/[รจรฉรชรซ]/g,"e");
	str = str.replace(/[รˆร‰รŠร‹]/g,"E");
	str = str.replace(/[รฏรฎ]/g,"i");
	str = str.replace(/[รรŽ]/g,"I");
	str = str.replace(/[รง]/g,"c");
	str = str.replace(/[ร‡]/g,"C");
	return str;
}


	function encodeunicode(seltxt, table) 
	{
		var text = "";
		//seltxt = seltxt.toLowerCase();
		seltxt = cleanUpSpecialChars(seltxt);
		var ok = false;
		for (var i =0; i< seltxt.length ; i++)
			{
				ok = false;
				for (var m = 0; m < alphabet.length;m++)
				{
					 if (alphabet[m] === seltxt[i]) 
					  {
						  text+=  table[m];
						  ok = true;
					  }
				}
				
				if (!ok )			
				{
					text+=seltxt[i];
				}
			}
		return text;
	}
	
	
})();