ImThatGuy / Audio stickers

// ==UserScript==
// @name         Audio stickers
// @author       ImThatGuy
// @description  Ajoute des sons aux stickers noelshacks JVC
// @include      http://www.jeuxvideo.com/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require      https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_xmlhttpRequest
// @version      1.1.2
// @icon         https://i.imgur.com/3HI8GPs.png
// @copyright    2018+, ImThatGuy
// @license      MIT
// @connect      jvcpremium.000webhostapp.com
// ==/UserScript==

/*
Audio stickers. 2018.
Developpé par ImThatGuy.

2018+, ImThatGuy.

Changelog :
Version 0.1.0 : 1ère version

Version 0.1.1 : Correction bug serveur offline

Version 0.1.2 : Possibilité de jouer n'importe quel son sans attendre que le précédent se termine
                Possibilité d'activer ou de désactiver l'affichage de l'icône "play" quand un son est joué
				Possibilité d'activer ou de désactiver la combinaison de sons
				Ajout des catégories : horreur & eussou
				Ajout de stickers

Version 0.1.3 : Ajout de stickers

Version 0.1.4 : Ajout de stickers & sons

Version 0.1.5 : Ajout de stickers & sons

Version 0.1.6 : Ajout de stickers & sons (flute, guitare, piano)

Version 1.0.0 : Ajout de stickers
                Ajout d'une option de pré-chargement de fichiers audio (possibilité de désactiver)
				Légères améliorations de design
Version 1.1.0 : Ajout de stickers
                Ajout d'une option permettant de stopper un son en enlevant la souris de celui-ci
Version 1.1.1 : Ajout de stickers & sons
Version 1.1.2 : Ajout des stickers & sons Soral
*/

/*jshint multistr: true */
/*jshint loopfunc:true */

(function() {
    'use strict';

	var $ = window.jQuery;
	const version = "1.1.2";


	$('head').append('<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">');
	$('head').append('<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pretty-checkbox@3.0/dist/pretty-checkbox.min.css"/>');


	var icon = GM_getValue("iconplay");
	if (icon === undefined) {
		GM_setValue("iconplay", true);
		icon = true;
	}

	var combine = GM_getValue("combine");
	if (combine === undefined) {
		GM_setValue("combine", false);
		combine = false;
	}

	var preload = GM_getValue("preload");
	if (preload === undefined) {
		GM_setValue("preload", true);
		preload = true;
	}

	var stop = GM_getValue("stop");
	if (stop === undefined) {
		GM_setValue("stop", false);
		stop = false;
	}


	var Main = [

		/* FANTASIO */
		{
			lien: ["https://image.noelshack.com/fichiers/2017/50/7/1513535874-fantaaa.png"],
			son: ["commentateurs.mp3", "lacrimatica.mp3", "cmtcpossibl.mp3", "cpastoikdecide.mp3", "pourquoi.mp3", "tuterendscompte.mp3"]
		},
		{
			lien: ["https://image.noelshack.com/fichiers/2017/50/7/1513535721-fantagueule.png"],
			son: ["tagueule.mp3"]
		},
		{
			lien: ["https://image.noelshack.com/fichiers/2017/50/7/1513535727-fantadegage.png"],
			son: ["degage.mp3"]
		},
		{
			lien: ["https://image.noelshack.com/fichiers/2017/50/7/1513535713-fantalacrimatica.png"],
			son: ["lacrimatica.mp3"]
		},
		{
			lien: ["https://image.noelshack.com/fichiers/2018/10/4/1520534114-lacrimaticapourquoi.png"],
			son: ["pourquoi.mp3"]
		},

		/* RISITAS CLASSIQUES */

		{
			lien: [
				"http://image.noelshack.com/fichiers/2016/24/1466366197-risitas10.png",
				"http://image.noelshack.com/fichiers/2016/38/1474794851-risitas766.gif",
				"https://image.noelshack.com/fichiers/2016/49/1481201791-yaahshs.png",
				"https://image.noelshack.com/fichiers/2017/50/1/1513020307-risitas54transparent2b.png",
				"https://image.noelshack.com/fichiers/2015/49/1448914032-elrisitasgif.gif",
				"http://image.noelshack.com/minis/2016/30/1469561699-1466004337-reupload-3-2.png",
				"http://image.noelshack.com/fichiers/2016/24/1466366188-risitas6.png",
				"http://image.noelshack.com/fichiers/2016/47/1479858878-1466366212-risitas32.png",
				"http://image.noelshack.com/fichiers/2016/24/1466366203-risitas21.png",
				"http://image.noelshack.com/fichiers/2017/03/1484921410-1466366200-risitas13.png",
				"http://image.noelshack.com/fichiers/2016/24/1466366197-risitas11.png",
				"https://image.noelshack.com/fichiers/2017/11/1489495205-voy-a-la-playa.png",
				"https://image.noelshack.com/fichiers/2017/13/1490644048-kfhy.png",
				"https://image.noelshack.com/fichiers/2017/17/1493199462-lcqos.png",
				"http://image.noelshack.com/fichiers/2016/47/1480092726-sans-titre-14.jpg",
				"http://image.noelshack.com/fichiers/2017/16/1492867274-14925389493.jpg",
				"http://image.noelshack.com/fichiers/2016/24/1466366339-risitas39.png"
			],
			son: ["issou.mp3", "issou2.mp3", "issou3.mp3", "issou4.mp3", "issou5.mp3", "issou7.mp3", "issou8.mp3", "issou9.mp3", "issou10.mp3", "issou11.mp3"]
		},
		{
			lien: [
				"http://image.noelshack.com/fichiers/2016/24/1466366342-risitas59.png",
				"https://image.noelshack.com/fichiers/2017/30/4/1501186981-risimixbestreup.png"
			],
			son: ["issou6.mp3", "issou10.mp3"]
		},
		{
			lien: [
				"http://image.noelshack.com/fichiers/2016/24/1466366296-risitas60.png",
				"https://image.noelshack.com/fichiers/2017/02/1483996280-1234434.jpg",
				"http://image.noelshack.com/fichiers/2017/03/1484789288-0243.jpg",
				"http://image.noelshack.com/fichiers/2016/47/1480250333-risitassueur.png",
				"http://image.noelshack.com/fichiers/2017/20/1495289536-doubletranspi.jpg",
				"http://image.noelshack.com/fichiers/2017/14/1491484186-risitasueur.png"
			],
			son: ["ahi.mp3", "ahi2.mp3"]
		},
		{
			lien: [
				"https://image.noelshack.com/fichiers/2016/24/1466366209-risitas24.png",
				"http://image.noelshack.com/fichiers/2018/10/4/1520546356-aaaaaaaya.png"
			],
			son: ["aaya.mp3"]
		},
		{
			lien: [
				"http://image.noelshack.com/fichiers/2016/46/1479639726-1467231909-1466015251-esp.png",
				"https://image.noelshack.com/fichiers/2018/29/6/1532128784-risitas33.png",
				"https://image.noelshack.com/fichiers/2017/39/3/1506463228-risibg.png",
				"https://image.noelshack.com/fichiers/2017/39/3/1506524542-ruth-perplexev2.png",
				"http://image.noelshack.com/fichiers/2016/50/1482027315-perplexe.png",
				"https://image.noelshack.com/fichiers/2016/41/1476650550-picsart-10-15-08-07-17.jpg",
				"https://image.noelshack.com/fichiers/2016/36/1473263957-risitas33.png",
				"https://image.noelshack.com/fichiers/2017/30/4/1501187858-risitassebestreup.png",
				"https://image.noelshack.com/fichiers/2016/42/1476947003-risitas-lunettes-main.png",
				"http://image.noelshack.com/fichiers/2017/30/4/1501184969-risitas33bestreup.png",
				"http://image.noelshack.com/fichiers/2016/47/1480081450-ris42.png",
				"http://image.noelshack.com/fichiers/2016/24/1466366648-risitas115.png",
				"http://image.noelshack.com/fichiers/2016/38/1474490297-risitas494.png",
				"http://image.noelshack.com/fichiers/2016/30/1469971032-risitas246.png",
				"http://image.noelshack.com/fichiers/2016/36/1473137273-up.png",
				"https://image.noelshack.com/fichiers/2016/42/1476948114-risitas-claque.png",
				"https://image.noelshack.com/fichiers/2016/48/1480464151-1474490323-risitas580.png",
				"http://image.noelshack.com/fichiers/2016/38/1474490319-risitas575.png",
				"http://image.noelshack.com/fichiers/2017/39/3/1506463228-risibg.png",
				"https://image.noelshack.com/fichiers/2017/21/1495823618-risitas596.png"
			],
			son: ["chancla.mp3", "chancla2.mp3"]
		},

		/* JESUS */
		{
			lien: [
				"https://image.noelshack.com/fichiers/2018/13/6/1522530708-jesusgif.gif",
				"http://image.noelshack.com/fichiers/2016/46/1479341443-issou.gif",
				"http://image.noelshack.com/fichiers/2016/38/1474488554-jesus18.png",
				"https://image.noelshack.com/fichiers/2018/19/3/1525860147-gobelin.png",
				"https://image.noelshack.com/fichiers/2017/18/1493833806-jesusroz.gif",
				"https://image.noelshack.com/fichiers/2017/08/1487945142-jesus.png",
				"http://image.noelshack.com/fichiers/2016/38/1474488632-jesus27.png",
				"http://image.noelshack.com/fichiers/2017/18/1493933263-fou-rire-jesus.png",
				"https://image.noelshack.com/minis/2018/19/3/1525860147-gobelin.png"
			],
			son: ["jesusrire.mp3"]
		},

		/* RISITAS AUTRES */
		{
			lien: [
				"https://image.noelshack.com/fichiers/2017/12/1490254840-16.png",
				"https://image.noelshack.com/fichiers/2017/19/1494539739-pfiggsq.png",
				"https://image.noelshack.com/fichiers/2017/05/1486154002-sans-titre-16.png",
				"https://image.noelshack.com/fichiers/2017/05/1486152731-sans-titre-18.png",
				"https://image.noelshack.com/fichiers/2017/09/1488318710-risitas14.png"
			],
			son: ["ah1.mp3", "ah2.mp3", "ah3.mp3", "ah4.mp3", "ah5.mp3"]
		},
		{
			lien: [
				"http://image.noelshack.com/fichiers/2016/30/1469541959-risitas206.png",
				"http://image.noelshack.com/fichiers/2016/38/1474797359-risitas770.gif",
				"https://image.noelshack.com/fichiers/2016/38/1474490235-risitas434.png",
				"https://image.noelshack.com/fichiers/2017/07/1487382298-risitasdepressif.png",
				"https://image.noelshack.com/fichiers/2017/01/1483561676-snifkermit.png",
				"https://image.noelshack.com/fichiers/2016/39/1474977784-risitasfpleure.png",
				"https://image.noelshack.com/fichiers/2017/23/1496925297-issoupleure.png",
				"https://image.noelshack.com/fichiers/2017/09/1488348680-risideprime.gif",
				"https://image.noelshack.com/fichiers/2016/47/1480081469-ris6.png",
				"http://image.noelshack.com/fichiers/2016/39/1474977832-sadchanclaloop.gif",
				"http://image.noelshack.com/fichiers/2016/52/1482821182-risadecepvierge.gif",
				"http://image.noelshack.com/fichiers/2017/31/1/1501456759-risitristebus.gif",
				"https://image.noelshack.com/minis/2016/39/1474977832-sadchanclaloop.png"
			],
			son: ["piano.mp3", "darkness.mp3"]
		},
		{
			lien: [
				"https://image.noelshack.com/fichiers/2018/25/2/1529422413-risitaszoom.png",
				"https://image.noelshack.com/fichiers/2018/10/1/1520260980-risitas94.png",
				"https://image.noelshack.com/fichiers/2016/30/1469541952-risitas182.png",
				"https://image.noelshack.com/fichiers/2018/10/1/1520256134-risitasue2.png",
				"https://image.noelshack.com/fichiers/2017/31/5/1501863678-risitas596bestreup.png",
				"https://image.noelshack.com/fichiers/2016/47/1480092147-1477945635-1465556572-elrisitassticker3-copy.png",
				"https://image.noelshack.com/fichiers/2017/30/4/1501186885-risitasueurbestreup.png",
				"https://image.noelshack.com/fichiers/2016/52/1483223370-1474698744-picsart-09-25-08-24-06.png",
				"http://image.noelshack.com/fichiers/2016/30/1469541968-risitas224.png",
				"http://image.noelshack.com/fichiers/2016/24/1466366602-risitas94.png"
			],
			son: ["ataoy.mp3", "yatangaki.mp3", "banador.mp3", "paellera.mp3"]
		},
		{
			lien: [
				"https://image.noelshack.com/fichiers/2017/39/3/1506463227-risitaspeur.png",
				"https://image.noelshack.com/fichiers/2016/50/1482000512-onsecalmerisitas.png",
				"http://image.noelshack.com/fichiers/2016/24/1466366261-risitas51.png",
				"http://image.noelshack.com/fichiers/2016/44/1478142991-risitas-question.png",
				"http://image.noelshack.com/fichiers/2017/14/1491249193-risitasg16462.png"
			],
			son: ["que.mp3"]
		},
		{
			lien: [
				"https://image.noelshack.com/fichiers/2016/26/1467335935-jesus1.png",
				"https://image.noelshack.com/fichiers/2018/13/4/1522325846-jesusopti.png",
				"http://image.noelshack.com/fichiers/2016/38/1474488637-jesus26.png"
			],
			son: ["jesus.mp3"]
		},
		// ISSOUS SPE
		{
			lien: [
				"https://image.noelshack.com/fichiers/2018/26/7/1530476579-reupjesus.png",
				"http://image.noelshack.com/fichiers/2016/36/1473263674-jesus5.png",
				"https://image.noelshack.com/fichiers/2017/31/5/1501862610-jesus56bestreup.png",
				"https://image.noelshack.com/fichiers/2018/27/4/1530827992-jesusreup.png",
				"http://image.noelshack.com/fichiers/2016/47/1480064732-1467335935-jesus4.png",
				"https://image.noelshack.com/fichiers/2017/02/1484039097-jesussssss.png",
				"https://image.noelshack.com/fichiers/2017/50/1/1513020307-jesusjointtransparent.png",
				"http://image.noelshack.com/fichiers/2017/12/1490458236-issou-chauve.png",
				"https://image.noelshack.com/fichiers/2017/21/1495486604-1466366197-risitas10.png",
				"http://image.noelshack.com/fichiers/2017/30/4/1501186981-risimixbestreup.png",
				"http://image.noelshack.com/fichiers/2017/30/4/1501185683-jesusjournalbestreup.png",
				"http://image.noelshack.com/fichiers/2016/32/1470920800-jesus14.png"
			],
			son: ["issouspe.mp3", "issouspe2.mp3", "issouspe3.mp3"]
		},
		// RISITAS TOUSSE
		{
			lien: [
				"https://image.noelshack.com/fichiers/2017/05/1486086060-bloggif-5893df21aaff2.png",
				"https://image.noelshack.com/fichiers/2017/13/1490735953-risitas802.png",
				"https://image.noelshack.com/fichiers/2017/05/1486213095-sans-titre-11.png",
				"https://image.noelshack.com/fichiers/2017/11/1489519474-00002272727.jpg",
				"https://image.noelshack.com/fichiers/2017/15/1491920437-risitas-tousse-test.gif",
				"http://image.noelshack.com/fichiers/2016/47/1480092405-1477945647-1465556572-elrisitassticker2-copy.png"
			],
			son: ["tousse.mp3", "tousse2.mp3"]
		},
		// ALERTE
		{
			lien: [
				"https://image.noelshack.com/fichiers/2017/30/4/1501186458-risitalarmebestreup.gif",
				"https://image.noelshack.com/fichiers/2017/01/1483903108-bloggif-5872902617ce6.gif",
				"https://image.noelshack.com/fichiers/2016/52/1482807062-alerte.gif",
				"https://image.noelshack.com/fichiers/2017/48/6/1512231347-jesusalert.gif",
				"https://image.noelshack.com/fichiers/2017/15/1492017614-atome.png",
				"https://image.noelshack.com/fichiers/2017/14/1491750430-elite.png",
				"https://image.noelshack.com/fichiers/2017/01/1483903109-bloggif-5872903951574.gif",
				"https://image.noelshack.com/fichiers/2017/15/1492046397-risitasmdrww3.gif",
				"https://image.noelshack.com/fichiers/2016/48/1480321136-alert2.jpg"
			],
			son: ["alerte.mp3"]
		},
		// HORREURS
		{
			lien: [
				"https://image.noelshack.com/fichiers/2017/19/1494279332-risicreepy2.png",
				"https://image.noelshack.com/fichiers/2017/19/1494275179-jesus-horreur-gif-ingenieurjvc.gif",
				"https://image.noelshack.com/fichiers/2017/19/1494243131-risitas-demoniaque-zoom-ingenieurjvc.png",
				"https://image.noelshack.com/fichiers/2017/19/1494361508-sata.png",
				"https://image.noelshack.com/fichiers/2017/11/1489495011-risitasdiable.gif",
				"https://image.noelshack.com/fichiers/2017/19/1494277380-creepysueur.png",
				"https://image.noelshack.com/fichiers/2017/19/1494275991-creepypapier.png",
				"https://image.noelshack.com/fichiers/2017/19/1494678588-risitasgentil.jpg",
				"https://image.noelshack.com/fichiers/2016/52/1482787765-issouception.gif",
				"https://image.noelshack.com/fichiers/2016/30/1469405738-risitas166.png",
				"https://image.noelshack.com/fichiers/2016/48/1480321136-risitas159.jpg",
				"https://image.noelshack.com/fichiers/2016/26/1467309320-risitas158.png",
				"https://image.noelshack.com/fichiers/2017/17/1493239980-aaaaaaaaah-euuuuuussssssssouuuuuuuuu.png"
			],
			son: ["horreur.mp3"]
		},
		// EUSSOU
		{
			lien: [
				"https://image.noelshack.com/fichiers/2017/17/1493289235-risibouchetrois.png",
				"https://image.noelshack.com/fichiers/2017/22/1496602541-singeeussou.png",
				"https://image.noelshack.com/fichiers/2017/18/1494194269-risibouchecinq.png",
				"https://image.noelshack.com/fichiers/2017/19/1494195269-risibouchequatre.png",
				"https://image.noelshack.com/fichiers/2017/18/1494151894-risimix.png",
				"https://image.noelshack.com/fichiers/2017/22/1496432637-1493289235-risibouchetroisquatre.png",
				"https://image.noelshack.com/fichiers/2017/17/1493237608-image.jpg",
				"https://image.noelshack.com/fichiers/2017/18/1494149225-mixjesus.png",
				"https://image.noelshack.com/fichiers/2017/18/1494155675-risibaille.png",
				"https://image.noelshack.com/fichiers/2017/18/1494165411-iffou.png",
				"https://image.noelshack.com/fichiers/2017/23/1496702653-1485131657-cant-steussou.png",
				"https://image.noelshack.com/minis/2017/41/3/1507722163-ddkk.png",
				"http://image.noelshack.com/fichiers/2017/42/4/1508437008-elbougnader.png"
			],
			son: ["eussou1.mp3", "eussou2.mp3", "eussou3.mp3", "eussou4.mp3"]
		},
		// Risitas sous l'eau - 0.1.4
		{
			lien: [
				"https://image.noelshack.com/fichiers/2016/48/1480464145-1472419034-picsart-08-01-05-58-28.jpg",
				"https://image.noelshack.com/fichiers/2017/09/1488720976-picsart-03-05-02-12-45.jpg",
				"https://image.noelshack.com/fichiers/2016/34/1471979979-picsart-08-23-09-16-48.jpg",
				"https://image.noelshack.com/fichiers/2016/31/1470494339-risitas265.png",
				"https://image.noelshack.com/fichiers/2017/14/1491769226-risishok-c.png",
				"https://image.noelshack.com/fichiers/2016/38/1474490321-risitas555.png"
			],
			son: ["underwater.mp3", "underwater2.mp3"]
		},
		// Risitas explosions - 0.1.5
		{
			lien: [
				"https://image.noelshack.com/fichiers/2017/15/1492017614-atome.png",
				"https://image.noelshack.com/fichiers/2017/15/1492363773-prato.png",
				"https://image.noelshack.com/fichiers/2017/15/1492189516-prionsatome.jpg",
				"https://image.noelshack.com/fichiers/2016/44/1478142847-risitas-explosion2.png",
				"https://image.noelshack.com/fichiers/2016/43/1477350421-1477172016-1476010016-666999777.png",
				"https://image.noelshack.com/fichiers/2017/07/1487018959-1472470603-risitas11-copie-copie-2.png",
				"https://image.noelshack.com/fichiers/2017/07/1487018959-1467335935-jesus1.png",
				"https://image.noelshack.com/fichiers/2016/48/1480449984-videotogif-2016-11-29-20-20-38.gif",
				"https://image.noelshack.com/fichiers/2017/20/1494973088-ddb-fdp.jpg",
				"https://image.noelshack.com/fichiers/2017/20/1494970520-hqdefault.jpg",
				"https://image.noelshack.com/fichiers/2018/21/5/1527266233-3-atome-bombe-issou.jpg",
				"http://image.noelshack.com/fichiers/2016/43/1477430393-risitas-ww3.gif",
				"http://image.noelshack.com/fichiers/2017/15/1492363773-prato.png"
			],
			son: ["explosion.mp3"]
		},
		// Risitas religion - 0.1.5
		{
			lien: [
				"https://image.noelshack.com/fichiers/2016/48/1480546095-risitas-moine2.png",
				"https://image.noelshack.com/fichiers/2016/48/1480540191-risitasprie.png",
				"https://image.noelshack.com/fichiers/2016/47/1480068404-moine.png",
				"https://image.noelshack.com/fichiers/2016/47/1480093278-1474550793-1474526631-picsart-09-23-08-38-29.png",
				"https://image.noelshack.com/fichiers/2016/41/1476521866-picsart-10-15-10-52-16.jpg",
				"https://image.noelshack.com/fichiers/2016/48/1480696893-picsart-12-02-05-39-02.jpg",
				"https://image.noelshack.com/fichiers/2016/48/1480876890-risitas-moine2.png",
				"https://image.noelshack.com/fichiers/2016/39/1474989155-1473106851-1472305016-picsart-08-24-08-51-08.jpg",
				"https://image.noelshack.com/fichiers/2016/38/1474550906-1474296663-1473485808-picsart-08-29-08-57-21.png",
				"https://image.noelshack.com/fichiers/2016/48/1480782455-picsart-12-03-03-31-34.jpg",
				"https://image.noelshack.com/fichiers/2016/38/1474563250-picsart-09-23-06-48-41.jpg",
				"https://image.noelshack.com/fichiers/2016/41/1476548283-picsart-10-15-06-16-46.jpg",
				"https://image.noelshack.com/fichiers/2016/32/1470675783-risitas-pape.png",
				"https://image.noelshack.com/fichiers/2016/50/1482082001-jesusssssss.png",
				"https://image.noelshack.com/fichiers/2017/18/1493774647-1479176457-pretrerisitas.png",
				"https://image.noelshack.com/fichiers/2016/38/1474550815-1474299886-picsart-09-20-05-35-43.png"
			],
			son: ["choir.mp3", "choir2.mp3", "choir3.mp3"]
		},
		// Risitas flute 0.1.6
		{
			lien: [
				"https://image.noelshack.com/fichiers/2016/41/1476355131-la-fluta.png",
				"https://image.noelshack.com/fichiers/2016/41/1476305152-risitasflutebykillerjamme-sansbordurenoir.png",
				"https://image.noelshack.com/fichiers/2016/49/1481221567-flutezoom.jpg",
				"https://image.noelshack.com/fichiers/2017/02/1483992269-www-gifcreator-me-bc0ubp.gif",
				"https://image.noelshack.com/fichiers/2017/09/1488373007-zz.jpg",
				"https://image.noelshack.com/fichiers/2016/41/1476306601-risitasflute2bykillerjamme.png",
				"https://image.noelshack.com/fichiers/2016/52/1483222765-1476305152-risitasflutebykillerjamme-inverse.png",
				"https://image.noelshack.com/fichiers/2017/04/1485459601-tenor.gif",
				"https://image.noelshack.com/fichiers/2017/06/1486469678-risitas-sarbacane.png",
				"https://image.noelshack.com/fichiers/2017/09/1488370373-risitasflutemacronzoom.png",
				"https://image.noelshack.com/fichiers/2017/06/1486469678-risitascharmeurdeserpents.png",
				"https://image.noelshack.com/fichiers/2017/12/1490043821-1488370373-risitasflutemacronzoom.png",
				"https://image.noelshack.com/fichiers/2017/03/1484886474-1482027315-perplexe.png",
				"https://image.noelshack.com/fichiers/2016/43/1477350499-risitasflute2-copie.jpg"
			],
			son: ["flute.mp3", "flute2.mp3"]
		},
		// Risitas piano 0.1.6
		{
			lien: [
				"https://image.noelshack.com/fichiers/2017/04/1485609917-ruthveun-piano-gif.gif",
				"https://image.noelshack.com/fichiers/2016/42/1476893510-picsart-10-19-05-54-35.jpg",
				"https://image.noelshack.com/fichiers/2017/02/1484433814-ruthveun-piano.png",
				"https://image.noelshack.com/fichiers/2017/04/1485455731-calipsy-ruthveun-macron.gif",
				"https://image.noelshack.com/fichiers/2017/01/1483651821-risitaspianiste.jpg",
				"https://image.noelshack.com/fichiers/2017/04/1485354280-capture-d-ecran-2017-01-18-a-23-51-59.png",
				"https://image.noelshack.com/fichiers/2017/03/1484780683-capture-d-ecran-2017-01-19-a-00-03-42.png",
				"https://image.noelshack.com/fichiers/2017/04/1485562422-capture-d-ecran-2017-01-28-a-01-13-20.png",
				"https://image.noelshack.com/fichiers/2018/15/7/1523783236-raysitas.png"
			],
			son: ["pianospe.mp3", "pianospe2.mp3"]
		},
		// Risitas guitare 0.1.6
		{
			lien: [
				"https://image.noelshack.com/fichiers/2016/40/1475519215-risitas-guitare2.png",
				"https://image.noelshack.com/fichiers/2017/14/1491605780-guitarerisitas.png",
				"https://image.noelshack.com/fichiers/2017/15/1491866092-risitas-guittare.gif",
				"https://image.noelshack.com/fichiers/2017/18/1494021319-johnnyrebel.png",
				"https://image.noelshack.com/fichiers/2017/44/2/1509470335-risi-troubadour.png",
				"https://image.noelshack.com/fichiers/2017/43/5/1509056636-mexi.png",
				"https://image.noelshack.com/fichiers/2017/43/5/1509058629-blc.png",
				"https://image.noelshack.com/fichiers/2018/32/2/1533642760-unknown.png"
			],
			son: ["guitar.mp3", "guitar2.mp3"]
		},
		// TAPE
		{
			lien: [
				"https://image.noelshack.com/fichiers/2016/38/1474488555-jesus24.png",
				"https://image.noelshack.com/fichiers/2017/18/1493759881-udqifg.png",
				"http://image.noelshack.com/fichiers/2018/38/1/1537217672-uhfgdt.png"
			],
			son: ["tap.mp3", "tap2.mp3"]
		},
		// Larry
		{
			lien: [
				"https://image.noelshack.com/fichiers/2017/12/1490182124-larrychance.png",
				"https://image.noelshack.com/fichiers/2017/12/1490019868-lachancesilversteinstickers.png",
				"https://image.noelshack.com/fichiers/2017/20/1494968374-pas-de-chance.png",
				"https://image.noelshack.com/fichiers/2017/19/1494619651-larryhome-2.png",
				"https://image.noelshack.com/fichiers/2017/04/1485484836-larry.png",
				"https://image.noelshack.com/fichiers/2017/20/1495032802-1485484836-larry-camoufle.png",
				"https://image.noelshack.com/fichiers/2017/23/1496920035-larrydance.gif",
				"https://image.noelshack.com/fichiers/2017/07/1487344471-larry-silverstein3.png",
				"https://image.noelshack.com/fichiers/2017/19/1494617394-larry3.png",
				"https://image.noelshack.com/fichiers/2017/23/1496929534-cizialarry.png",
				"https://image.noelshack.com/fichiers/2017/19/1494361757-larryb.png",
				"https://image.noelshack.com/fichiers/2017/19/1494617782-larryhome.png",
				"http://image.noelshack.com/fichiers/2017/19/1494701675-larrymonami.png"
			],
			son: ["home.mp3", "youknow.mp3"]
		},
		// Ronaldo
		{
			lien: [
				"https://image.noelshack.com/fichiers/2017/11/1489483757-cr7-2.png",
				"https://image.noelshack.com/fichiers/2017/11/1489483754-cr7-1.png",
				"https://image.noelshack.com/fichiers/2018/10/2/1520362735-1.png",
				"https://image.noelshack.com/fichiers/2018/19/2/1525803441-ronaldo-jesusperplexesourire200x150.png",
				"https://image.noelshack.com/fichiers/2018/25/2/1529410213-1526410779-jesus-xxxronaldo2.png",
				"https://image.noelshack.com/minis/2018/07/4/1518670200-4466792a-9f47-4cc3-b02d-3f235b7d36d0.png",
				"http://image.noelshack.com/fichiers/2018/11/6/1521297524-cr7684x513.png",
				"http://image.noelshack.com/fichiers/2018/15/4/1523563764-1523394470-1499613727-alkpote-cr7-sun.png",
				"http://image.noelshack.com/fichiers/2018/17/4/1524775878-cr7ent.png"
			],
			son: ["ronaldo.mp3"]
		},
		// Soral (1.1.2)
		{
			lien: [
				"https://image.noelshack.com/fichiers/2017/18/1493613163-soral12.png",
				"https://image.noelshack.com/fichiers/2016/51/1482171512-chhhchhh.png",
				"https://image.noelshack.com/fichiers/2017/11/1489434436-soral8.png",
				"https://image.noelshack.com/fichiers/2017/11/1489434436-soral4.png",
				"https://image.noelshack.com/fichiers/2017/10/1489274842-iphone-image-03-12-2017.jpg",
				"https://image.noelshack.com/fichiers/2017/08/1487789621-soralcherch1.png",
				"https://image.noelshack.com/fichiers/2017/11/1489434654-soral1.png",
				"https://image.noelshack.com/fichiers/2016/51/1482270678-soraldeter.png",
				"https://image.noelshack.com/fichiers/2016/49/1481408202-1481406963-1481143319-1481119998-soral.png",
				"https://image.noelshack.com/fichiers/2016/51/1482325320-soral-deter.jpg",
				"https://image.noelshack.com/fichiers/2016/50/1482097337-1481207549-thisissoral.png",
				"https://image.noelshack.com/fichiers/2017/11/1489434436-soral5.png",
				"https://image.noelshack.com/fichiers/2017/17/1493036541-soral-conversano.gif",
				"https://image.noelshack.com/fichiers/2017/20/1494946966-larrysoral.png",
				"https://image.noelshack.com/fichiers/2017/51/4/1513862207-ob-c2f6fd-1481377436-imlyk8b.gif"
			],
			son: ["soral.mp3", "soral2.mp3", "soral3.mp3"]
		},
		// Conversano (1.1.2)
		{
			lien: [
				"https://image.noelshack.com/fichiers/2016/49/1481123165-baston.png",
				"https://image.noelshack.com/fichiers/2017/18/1493925101-1481967345-1481213139-tu-es-un-bourgeois-soral.png",
				"https://image.noelshack.com/fichiers/2017/07/1487209767-non-je-ne-te-respecte-pas.png",
				"https://image.noelshack.com/fichiers/2017/11/1489826477-conversano-penseur-grand.png",
				"https://image.noelshack.com/fichiers/2017/08/1488137164-conversano.png",
				"https://image.noelshack.com/fichiers/2018/24/1/1528726275-1528726043-conversanopaumeancestral2.png",
			],
			son: ["conversano.mp3", "conversano2.mp3", "conversano3.mp3"]
		}
	];


    function listeSujet() {
        if (document.getElementsByName('search_in_forum').length === 0) {
            return false;
        } else {return true;}
    }


	function splitShit(str) {
		var a = str;
		var index = a.indexOf("/");
		var id = a.substr(0, index);
		var text = a.substr(index + 1);

		return text
	}

	function setAudios() {
		for (var i=0; i<Main.length;i++) {

			for (var t=0; t<Main[i].lien.length;t++) {
				var lien = Main[i].lien[t];

				$(".img-shack").each(function() {

					if ( splitShit($(this).attr("alt")) == splitShit(lien) ) {

						var son = Main[i].son[Math.floor(Math.random()*Main[i].son.length)];
						$(this).attr("son", "https://jvcpremium.000webhostapp.com/audiostickers/sons/"+son);

					}

				});
			}
		}

	}

	// Paramètres checkboxes
	var checkboxIcon; // Icon play
	if (icon) {
		checkboxIcon = '<div class="pretty p-default p-curve" style="font-size:11px;"> <input type="checkbox" id="iconplay" checked> <div class="state p-info-o"><label style="margin-left:3px"> Désactiver l\'icône play</label></div></div><br>';
	} else {
		checkboxIcon = '<div class="pretty p-default p-curve" style="font-size:11px;"> <input type="checkbox" id="iconplay"> <div class="state p-info-o"><label style="margin-left:3px"> Activer l\'icône play</label></div></div><br>';
	}

	var checkboxCombine; // Combiner les sons
	if (combine) {
		checkboxCombine = '<div class="pretty p-default p-curve" style="font-size:11px;"> <input type="checkbox" id="combine" checked> <div class="state p-info-o"><label style="margin-left:3px"> Désactiver la combinaison de son</label></div></div><br>';
	} else {
		checkboxCombine = '<div class="pretty p-default p-curve" style="font-size:11px;"> <input type="checkbox" id="combine"> <div class="state p-info-o"><label style="margin-left:3px"> Activer la combinaison de son</label></div></div><br>';
	}

	var checkboxPreload; // Préchargement sons
	if (preload) {
		checkboxPreload = '<div class="pretty p-default p-curve" style="font-size:11px;"> <input type="checkbox" id="preload" checked> <div class="state p-info-o"><label style="margin-left:3px"> Désactiver le préchargement des sons</label></div></div><br>';
	} else {
		checkboxPreload = '<div class="pretty p-default p-curve" style="font-size:11px;"> <input type="checkbox" id="preload"> <div class="state p-info-o"><label style="margin-left:3px"> Activer le préchargement des sons</label></div></div><br>';
	}

	var checkboxStop; // Préchargement sons
	if (stop) {
		checkboxStop = '<div class="pretty p-default p-curve" style="font-size:11px;"> <input type="checkbox" id="stop" checked> <div class="state p-info-o"><label style="margin-left:3px"> Désactiver l\'arrêt après passage de la souris</label></div></div><br>';
	} else {
		checkboxStop = '<div class="pretty p-default p-curve" style="font-size:11px;"> <input type="checkbox" id="stop"> <div class="state p-info-o"><label style="margin-left:3px"> Activer l\'arrêt après passage de la souris</label></div></div><br>';
	}

	// Append
	$("div.bloc-info-forum").append('<h4 class="titre-info-fofo">Audio stickers v '+version+'</h4>\
<div class="audiostickers">Serveur audio : <span style="color:red; font-family: Consolas;" id="audioStatus"> <i class="fa fa-times-circle"></i> Inactif</span><br/><br>\
<div class="sc-cadre"><span class="sc-titre">Paramètres</span>'+checkboxIcon+checkboxCombine+checkboxPreload+checkboxStop+'</div>\
</div>');
	if (preload) {
		$(".audiostickers").append('<br/><div class="sc-cadre"><span class="sc-titre">Préchargement</span>\
<div id="preload" style="font-size:11px;"><span id="nbsonscharge">0</span> / <span id="nbsons" style="font-size:11px;">?</span> fichier(s) chargé(s).</div>\
</div>');
	}

	// LISTENERS
	$('#iconplay').change(function() {
		if (this.checked) {
			GM_setValue("iconplay", true);
			location.reload();
		} else {
			GM_setValue("iconplay", false);
			location.reload();
		}
	});

	$('#combine').change(function() {
		if (this.checked) {
			GM_setValue("combine", true);
			location.reload();
		} else {
			GM_setValue("combine", false);
			location.reload();
		}
	});

	$('#preload').change(function() {
		if (this.checked) {
			GM_setValue("preload", true);
			location.reload();
		} else {
			GM_setValue("preload", false);
			location.reload();
		}
	});

	$('#stop').change(function() {
		if (this.checked) {
			GM_setValue("stop", true);
			location.reload();
		} else {
			GM_setValue("stop", false);
			location.reload();
		}
	});


	function active() {
		if (!listeSujet()) {

			setAudios();
			$(".audiostickers").append('<a class="audiost-btn"><i class="fa fa-times-circle"></i> Désactiver</a>');

			// Désactiver script
			$(".audiost-btn").click(function() {
				$(".img-shack").unbind("hover");
				$(this).replaceWith('<span style="position:absolute;top:0;right:0;font-size:11px;">Script désactivé.</span>');
			});

			$(".img-shack").hover(function() {
				//if (playing === false) {
					playAudio( $(this).attr('son'), $(this));
					setAudios();
				//}
			}, function() {
				if (stop) { // Version 1.1
					audio.pause();
					audio.currentTime = 0;
					$(this).prev().remove(); // Enlève l'icon play
				}
			});

		}
	}

	// Preload (api)

	// Combien de fichiers sons contient le serveur

	// Var global > nombre de fichiers
	if (preload && !listeSujet()) {
		var nombreFichiers = 0;

		GM_xmlhttpRequest({
			method: "GET",
			url: "https://jvcpremium.000webhostapp.com/audiostickers/api/?p=nombre",
			onload: function(response) {

				var e = JSON.parse( response.responseText );
				nombreFichiers = e.nombre;
				$("#nbsons").empty().append(e.nombre);


			}
		});


		GM_xmlhttpRequest({
			method: "GET",
			url: "https://jvcpremium.000webhostapp.com/audiostickers/api/?p=liste",
			onload: function(response) {

				var e = JSON.parse( response.responseText );
				var sons = e.liste;

				preloadAudio(sons);
				//console.log(sons.length);


			}
		});

		function preloadAudio(array) {
			for(var i=0; i<array.length; i++) {
				//console.log(sons[i]);
				loadFile(array[i], array, i);
			}
		}

		function loadFile(file, liste, index) {
			new Audio("https://jvcpremium.000webhostapp.com/audiostickers/sons/"+file).oncanplaythrough = function() {

				liste.splice(index, 1);

				var nbsons = parseInt($("#nbsonscharge").text())+1;
				var final;
				if (nbsons >= nombreFichiers) {
					final = nbsons;
					console.log("[AudioStickers] Tous les fichiers sont chargés.");
				} else {
					//final = nbsons + " (.."+file+"..)";
					final = nbsons;
				}
				$("#nbsonscharge").empty().append("<i>"+final+"</i>");
				//console.log(liste);
			}
			/*
			GM_xmlhttpRequest({
				method: "GET",
				url: "https://jvcpremium.000webhostapp.com/audiostickers/sons/"+file,
				onload: function(response) {
					//console.log(file+" chargé.");
					var nbsons = parseInt($("#nbsonscharge").text())+1;
					var final;
					if (nbsons >= nombreFichiers) {
						final = nbsons;
					} else {
						final = nbsons + "("+file+")";
					}
					$("#nbsonscharge").empty().append("<i>"+final+"</i>");
				}
			});
			*/
		}
	}

	// Tester le serveur & activer le script si online
	GM_xmlhttpRequest({
		method: "GET",
		url: "https://jvcpremium.000webhostapp.com/audiostickers/sons/issou.mp3",
		onload: function(response) {
			$("#audioStatus").empty();
			if (
				response.status == 200 || /* Tous les code HTTP de succès */
				response.status == 201 ||
				response.status == 202 ||
				response.status == 203 ||
				response.status == 204 ||
				response.status == 205 ||
				response.status == 206
			) {
				active();
				$("#audioStatus").append('<i class="fa fa-check-circle"></i> Actif');
				$("#audioStatus").css("color", "lime");
			} else {
				// N'active pas le script
				$("#audioStatus").append('<i class="fa fa-times-circle"></i> Inactif');
				$("#audioStatus").css("color", "red");
			}
		}
	});


	var playing = false;
	var audio = new Audio("");
	var dataSave = "";
	var sonSave = "";


	function playAudio(son, data) {
		if (son) {

			if (!audio.paused && sonSave == son) {
				console.log("L'audio est déjà entrain de se jouer.");
			} else {
				if (!combine) {
					audio.pause();
					$(dataSave).prev().remove();
				}

				dataSave = data;
				sonSave = son;

				audio = new Audio(son);
				audio.type = 'audio/wav';

				audio.play();
				playing = true;

				son = son.split("/");
				console.log('"'+son[son.length-1] +'" lecture.');


				// Ajoute le l'icône play
				if (icon) {
					$('<b style="position: absolute; color: #fff!important; text-shadow: 0px 1px 2px #222;" class="fa fa-play-circle"></b>').insertBefore(data);
					audio.addEventListener('ended', function() {
						//$(data).css("opacity", 1);
						$(data).prev().remove();
						playing = false;
					});
				}
			}

		}

	}

	GM_addStyle(".audiostickers { position: relative; }\
				.audiost-btn { color: #ddd;\
				padding-left: 4px; padding-right: 4px; padding-top: 2px; padding-bottom: 2px;\
                margin-bottom: 3px;\
                position: absolute;\
                cursor: pointer;\
                top: 0px;\
                right:0px;\
                border: 1px solid #aaa;\
                border-radius: 3px;\
                font-size: 11px;\
                background-color: #333;\
                transition: 0.1s;\
}");
	//GM_addStyle(".audiost-btn:hover { background-color: #eee; }");
	GM_addStyle(".audiost-btn:hover { color: #f24b4b!important; border-color: #f24b4b!important; background-color: #211d1d }\
				.audiost-btn:active { color: red!important; border-color: red!important; background-color: #211d1d }");
	GM_addStyle(".sc-titre { font-size: 11px; color: #ccc; font-family: 'robotoboldcondensed',Arial,Helvetica,sans-serif; position:absolute; top:2px; right:4px; }\
                 .sc-cadre { position:relative; border: 1px solid #555; padding: 5px; border-radius: 2px; }");

})();