Benissou / Hidden Stickers

// ==UserScript==
// @name         Hidden Stickers
// @author       Benissou
// @description  Hidden Stickers
// @include      http://www.jeuxvideo.com/forums*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_notification
// @grant        GM_xmlhttpRequest
// @grant        GM_getResourceText
// @grant        GM_getResourceURL
// @version      0.2.0
// @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"];

var stickers = [];
var stickersIMG = [];
var stickersID = [];
for(var h= 15;h<26;h++)
{
    for(var i=0; i<26; i++)
    {
        for(var j=0; j<26; j++)
        {
            stickers.push("[[sticker:p7s/1" + alphabet[h] + alphabet[i]+ alphabet[j]+"]]");
            stickersIMG.push("http://jv.stkr.fr/p7s/1"+ alphabet[h]  + alphabet[i]+ alphabet[j]);
            stickersID.push(alphabet[h] + alphabet[i]+ alphabet[j]);
     }
}
}

(function() {
    'use strict';

	GM_addStyle('#jv-Hstickers .modal-generic-main {width: 630px;margin-top: 184.5px !important;}');
	GM_addStyle('.Hstickers {cursor: pointer;}');
	GM_addStyle('#Hstickersclose {cursor: pointer;}');
    GM_addStyle('.HStkTitre { font-weight: bold;text-transform: uppercase;;text-align: center; padding:5px;margin-bottom:0px; border:1,1,0,0 solid rgba(0,0,0,0.3); background:rgba(0,0,0,0.3);}');
    GM_addStyle('.HStkListe {text-align: center; padding:5px; margin-top:0px; border:1px solid rgba(0,0,0,0.3); background:rgba(0,0,0,0.2);}');
	var node = document.createElement("button");
	node.className =  "btn btn-jv-editor-toolbar";
	node.type ="button";
	node.name ="Hstickers";
	node.id = "Hstickers";
	document.getElementsByClassName("btn-group")[2].appendChild(node);

	$('#Hstickers').append('<span  style="color:#a90;"><img src="http://image.noelshack.com/fichiers/2017/34/7/1503854222-150385454155404.png" style="width:16px;height:16px;"></span>');
    $('body').append('<div class="modal-generic modal-generic-scroll active" id="jv-Hstickers" style="display: none;">\
	<div class="modal-generic-main" style="margin-top: 0px;">\
	<a  class="modal-generic-close" id="Hstickersclose" ><span class="icon-close-popin-jv"></span></a>\
	<div class="modal-generic-header">HStickers</div>\
	<div class="modal-generic-content" id="Hstickers-list">\
	</div></div></div>');


	function appendArray (array)
	{
		var list = "";
		for(var i=0;i<array.length;i++)
		{
			list+= "<span><img class=\"Hstkr\" id=\""+ i +"\" src=\"" + array[i] + "\" style=\"width:68px;height:51px; background:#fff;;margin:2px!important;\"></span>";
		}
		$('#Hstickers-list').append("<p class='HStkListe'>"+ list + "</p>");


	}


	$('#Hstickers-list').append("<p class='HStkTitre'>Risitas</p>");
	appendArray(stickersIMG);

	document.getElementById('Hstickers').addEventListener('click', function() {popup("open");});
	document.getElementById('Hstickersclose').addEventListener('click', function() {popup("close");});

	var classname = document.getElementsByClassName("Hstkr");

	for (var i =0; i < classname.length-1; i++) {
		classname[i].addEventListener('click', function() {addemo(this);});
	}


	function addemo (ele)
	{
		popup("close");
		elem.value = elem.value.substring(0,start) + " " + stickers[ele.id] + " " + elem.value.substring(end,len);
	}

	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);


	// POPUP
	function popup (type)
	{
		if(type=="close")
		{
			document.getElementById("jv-Hstickers").style.display = "none";
		}
		else
		{
			elem = document.getElementById('message_topic');
			start = elem.selectionStart;
			end = elem.selectionEnd;
			len = elem.value.length;
			sel_txt = elem.value.substring(start,end);
			document.getElementById("jv-Hstickers").style.display = "block";
		}
	}


})();