Dreadcast Chat Enhancer

Améliore le chat de Dreadcast.

  1. // ==UserScript==
  2. // @name Dreadcast Chat Enhancer
  3. // @namespace https://greasyfork.org/scripts/21359-dreadcast-chat-enhancer/
  4. // @version 2.3.17
  5. // @description Améliore le chat de Dreadcast.
  6. // @author MockingJay, Odul, Ladoria, Isilin
  7. // @match https://www.dreadcast.eu/Main
  8. // @match https://www.dreadcast.net/Main
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @grant GM_deleteValue
  12. // @grant GM_listValues
  13. // @license http://creativecommons.org/licenses/by-nc-nd/4.0/
  14. // ==/UserScript==
  15.  
  16. //Lit les variables dans GM à la demande. A utiliser pour chaque déclaration de variable qui est copiée en mémoire.
  17. //initValue: Valeur par défaut de la variable, qu'on lui donne à la déclaration et qu'elle garde si pas d'équivalent en mémoire. localVarName: Valeur GM locale.
  18. function initLocalMemory(defaultValue, localVarName) {
  19. if (GM_getValue(localVarName) === undefined) {
  20. GM_setValue(localVarName, defaultValue);
  21. return defaultValue;
  22. } else {
  23. return GM_getValue(localVarName);
  24. }
  25. }
  26.  
  27. function rgb2hex(orig){
  28. var rgb = orig.replace(/\s/g,'').match(/^rgba?\((\d+),(\d+),(\d+)/i);
  29. return (rgb && rgb.length === 4) ? "#" +
  30. ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
  31. ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
  32. ("0" + parseInt(rgb[3],10).toString(16)).slice(-2) : orig;
  33. }
  34.  
  35. $(document).ready(function() {
  36.  
  37. //**********************************************
  38. // DECLARATION DES VARIABLES
  39. //**********************************************
  40.  
  41. //CONSTANTES
  42. const W_ZONE_CHAT = 317; //Largeur de base des différents éléments du chat.
  43. const W_MSG = 290;
  44. const W_CHATCONTENT = 308; //Valeur pas d'origine, mais nécessaire pour le script.
  45. const W_CHAT = 328;
  46. const W_ONGLETS_CHAT = 254;
  47. const W_CHATFORM = 288;
  48.  
  49. const DEFAULT_CHAT_COLOR = rgb2hex($("#zone_chat .zone_infos").css("color"));
  50. $('<div class="couleur5" style="display:none;"></div>').appendTo("body");
  51. const DEFAULT_CHAT_COLOR5 = ($(".couleur5").css("color") !== undefined) ? rgb2hex($(".couleur5").css("color")) : "#999";
  52. $('<div class="couleur4" style="display:none;"></div>').appendTo("body");
  53. const DEFAULT_CHAT_COLOR4 = ($(".couleur4").css("color") !== undefined) ? rgb2hex($(".couleur4").css("color")) : "#999";
  54. $('<div class="couleur_rouge" style="display:none;"></div>').appendTo("body");
  55. const DEFAULT_CHAT_COLOR_RED = ($(".couleur_rouge").css("color") !== undefined) ? rgb2hex($(".couleur_rouge").css("color")) : "#D32929";
  56.  
  57. const DEFAULT_ZONE_DROITE_BG = $("#zone_droite").css("background"); //Permet de restituer le fond d'origine (ou de skin) de la zone droite lorsque le chat est à sa largeur initiale.
  58. const DEFAULT_SCRIPT_ZONE_DROITE_BG = 'https://i.imgur.com/kPzRqS2.png';
  59. const DEFAULT_SCRIPT_ZONE_CHAT_BG = 'https://i.imgur.com/0J3wOK0.png';
  60.  
  61. const DEFAULT_ALERT_CHAT_AUDIO_URL = 'https://www.dreadcast.net/sons/dcce.mp3';
  62.  
  63. //Initialisation variables de préférences
  64. var autoScroll = initLocalMemory(false, "DCCE_autoScroll");
  65. var scrollBar = initLocalMemory(true, "DCCE_scrollBar");
  66. var typePredict = initLocalMemory(true, "DCCE_typePredict");
  67. var alertVolume = initLocalMemory(1, "DCCE_alertVolume");
  68. var chatExtend = initLocalMemory(0, "DCCE_chatExtend");
  69.  
  70. const mrpDefaultCommands = [
  71. { alias:"env", name:"Environment", color:"#00FF00", bold:false, rp:true },
  72. { alias:"sis", name:"Ta soeur", color:"#00FFFF", bold:true, rp:false },
  73. { alias:"creepy", name:"Le Monstre", color:"#FF6464", bold:false, rp:true }
  74. ];
  75. var mrpCommandsString = initLocalMemory(JSON.stringify(mrpDefaultCommands), "DCCE_MRP");
  76. var mrpCommands = JSON.parse(mrpCommandsString);
  77.  
  78. var scriptZoneDroiteBG = initLocalMemory(DEFAULT_SCRIPT_ZONE_DROITE_BG, "DCCE_scriptZoneDroiteBG");
  79. var scriptZoneChatBG = initLocalMemory(DEFAULT_SCRIPT_ZONE_CHAT_BG, "DCCE_scriptZoneChatBG");
  80.  
  81. var alertChatAudioURL = initLocalMemory(DEFAULT_ALERT_CHAT_AUDIO_URL, "DCCE_alertChatAudioURL");
  82. var activateAlertChat = initLocalMemory(false, "DCCE_activateAlertChat");
  83.  
  84. var chatWidthStyle = $('<style id="chatWidthStyle">').appendTo("head"); //Utilisation d'une règle CSS car objets créés dynamiquement.
  85.  
  86. var chatEmoteStyle = $('<style id="chatEmoteStyle">span[style*="color:#58DCF9;"] em{color: ' + DEFAULT_CHAT_COLOR + ';}</style>').appendTo("head"); //Règle CSS pour appliquer la couleur du skin aux emotes. Visible uniquement côté client.
  87. var chatEmoteStyleWe = $('<style id="chatEmoteStyleWe">.msg.couleur5 span[style*="color:#58DCF9;"] em{color: ' + DEFAULT_CHAT_COLOR5 + ';}</style>').appendTo("head");
  88. var chatEmoteStyleYe = $('<style id="chatEmoteStyleYe">.msg.couleur_rouge span[style*="color:#58DCF9;"] em{color: ' + DEFAULT_CHAT_COLOR_RED + ';}</style>').appendTo("head");
  89. var chatEmoteStyleSpeech = $('<style id="chatEmoteStyleSpeech">.msg em span[style*="color:#FFFFFF;"]{font-style: normal;}</style>').appendTo("head"); //Redresse les paroles dans des emotes
  90. //Un non-utilisateur du script aura la couleur de base bleu clair.
  91.  
  92. //**********************************************
  93. // DECLARATION DES FONCTIONS, MISE EN PLACE DU CSS
  94. //**********************************************
  95.  
  96. $("#chatContent").css({
  97. "overflow-x": 'hidden',
  98. "overflow-y": 'scroll',
  99. //height: '313px', //width traitée dans setChatCSS
  100. "height": '100%',
  101. });
  102.  
  103. //Applique la barre de défilement en fonction des préférences, et règle la largeur des lignes dans le chat.
  104. function setChatContentScroll() {
  105. if(scrollBar) {
  106. $("#chatContent").css({"overflow-y": 'scroll'});
  107. }
  108. else {
  109. $("#chatContent").css({"overflow-y": 'hidden'});
  110. }
  111. }
  112.  
  113.  
  114. var $dcce_background = $('<div id="dcce_background"></div>').prependTo($("#zone_page")).css({left: '907px', top: '142px', height: '461px'}).css({display: 'none'});
  115.  
  116. function setZoneChatBackground() {
  117. if(chatExtend > 0) {
  118. $dcce_background.css({background: 'url("' + scriptZoneChatBG + '")',
  119. "background-size": '100% 100%',
  120. width: (W_ZONE_CHAT + 13 + chatExtend) + 'px'});
  121. $("#zone_droite").css({background: 'url("' + scriptZoneDroiteBG + '")'});
  122. } else {
  123. $dcce_background.css({
  124. background: 'none',
  125. width: '0px'
  126. });
  127. $("#zone_droite").css({background: DEFAULT_ZONE_DROITE_BG});
  128. }
  129. }
  130.  
  131. function setChatCSS() {
  132. setChatContentScroll();
  133. /*setZoneChatBackground();
  134. //Fixer les largeurs restantes
  135. $("#chatContent").width(W_CHATCONTENT + chatExtend);
  136. $("#zone_chat .zone_infos .chat").width(W_CHAT + chatExtend);
  137. $("#zone_chat #onglets_chat").width(W_ONGLETS_CHAT + chatExtend);
  138. $("#chatForm").width(W_CHATFORM + chatExtend);*/
  139. }
  140.  
  141. setChatCSS();
  142.  
  143. //Initialisation du bouton d'alerte, utilisé quand l'autoScroll est désactivé.
  144. var $newMessageAlert = $('<div />').appendTo($('#zone_chat'));
  145. $newMessageAlert.text("⚠ Nouveau message! ⚠");
  146. $newMessageAlert.css({
  147. display: 'none',
  148. top: '45px',
  149. "text-align": 'center',
  150. cursor: 'pointer',
  151. background: '#fff',
  152. border: '1px solid #fff',
  153. color: '#0296bb',
  154. "margin-top": '2px',
  155. "-webkit-box-shadow": '0 0 4px 2px #329bc2',
  156. });
  157. $newMessageAlert.attr('onmouseover', 'this.style.backgroundColor=\"#0b9bcb\";this.style.color=\"#FFFFFF\";');
  158. $newMessageAlert.attr('onmouseout', 'this.style.backgroundColor=\"#FFFFFF\";this.style.color=\"#0296bb\";');
  159.  
  160. //Initialisation bandeau latéral
  161. var $toggleAutoScroll = $('<li id="toggleAutoScroll" class="couleur5" ></li>'+'<li class="separator"></li>').prependTo($('#bandeau ul.menus'));
  162. if(autoScroll) {
  163. $("#toggleAutoScroll").text("AS on");
  164. } else {
  165. $("#toggleAutoScroll").text("AS off");
  166. }
  167. $("#toggleAutoScroll").css({
  168. cursor: 'pointer',
  169. });
  170. //$("#toggleAutoScroll").attr('onmouseover', 'this.style.color=\"#0073d5\";');
  171. //$("#toggleAutoScroll").attr('onmouseout', 'this.style.color=\"#999\";');
  172. $("#toggleAutoScroll").hover(
  173. function(){
  174. $(this).css("color", "#0073d5");
  175. },
  176. function(){
  177. var colorAS = autoScroll ? "#999" : "#D00000";
  178. $(this).css("color", colorAS);
  179. }
  180. );
  181. //Changer l'autoscroll au clic sur le bandeau latéral.
  182. $("#toggleAutoScroll").click(function(){
  183. if(autoScroll) {
  184. autoScroll = false;
  185. $("#toggleAutoScroll").text("AS off");
  186. } else {
  187. autoScroll = true;
  188. $("#toggleAutoScroll").text("AS on");
  189. }
  190. GM_setValue("DCCE_autoScroll", autoScroll);
  191. });
  192.  
  193. //Fait défiler le chat jusqu'en bas.
  194. function scrollChat(){
  195. $('#chatContent').stop().animate({
  196. scrollTop: $('#chatContent')[0].scrollHeight
  197. }, 800);
  198. $newMessageAlert.stop().fadeOut(500);
  199. }
  200.  
  201. var colorTagStyle = $('<style id="colorTagStyle">').prependTo("head"); //Utilisation d'une règle CSS car objets créés dynamiquement.
  202.  
  203. function chatChangeColor(id) {
  204. var persoName = GM_getValue("dcce_name_" + id);
  205. var colorRule = GM_getValue("dcce_ctb_" + id);
  206. if (colorRule === undefined) colorRule = DEFAULT_CHAT_COLOR;
  207.  
  208. var newRule = `.c${persoName} {color: ${colorRule};}
  209. .couleur5 .c${persoName} {color: ${DEFAULT_CHAT_COLOR5};}
  210. .couleur5 .c${persoName}.couleur4 {color: ${DEFAULT_CHAT_COLOR4};}`;
  211.  
  212. colorTagStyle.text(colorTagStyle.text() + newRule);
  213.  
  214. }
  215.  
  216. function initChatColor() {
  217. var localValues = GM_listValues();
  218. for(var i = 0; i < localValues.length; i++) {
  219. if(localValues[i].includes("dcce_ctb_")) {
  220. chatChangeColor(localValues[i].slice(9));
  221. }
  222. }
  223. }
  224. initChatColor();
  225.  
  226. //**********************************************
  227. //INTERFACE DE CONFIGURATION UTILISATEUR
  228. //**********************************************
  229. var $databox = $('#zone_dataBox');
  230. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  231. //Constructeur de fenêtre de configuration
  232. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  233. var DCCE_ConfigurationWindow = function () {
  234. var window_width = '560px';
  235. var window_height = '450px';
  236. var $config_window = $('<div id="dcce_configwindow" onclick="engine.switchDataBox(this)"/>');
  237. $config_window.draggable();
  238. $config_window.addClass('dataBox focused ui-draggable');
  239. $config_window.css({
  240. width: window_width,
  241. "margin-left": '-185px',
  242. display: 'block',
  243. position: 'absolute',
  244. "z-index": '2',
  245. });
  246. for (var i = 1; i <= 8; i++) {
  247. $('<div class="dbfond' + i + '" />').appendTo($config_window);
  248. }
  249. var $config_head = $('<div class="head ui-draggable-handle" ondblclick="$(\'#dcce_configwindow\').toggleClass(\'reduced\');" />').appendTo($config_window);
  250. $('<div title="Fermer la fenêtre (Q)" class="info1 link close" onclick="engine.closeDataBox($(this).parent().parent().attr(\'id\'));">X</div>').appendTo($config_head);
  251. $('<div title="Reduire/Agrandir la fenêtre" class="info1 link reduce" onclick="$(\'#dcce_configwindow\').toggleClass(\'reduced\');">-</div>').appendTo($config_head);
  252. $('<div class="title">Configuration DC Enhanced Chat</div>').appendTo($config_head);
  253. $('<div class="dbloader" />').appendTo($config_window);
  254. var $config_content = $('<div class="content" style="height:' + window_height + '; overflow: auto"/>').appendTo($config_window);
  255. //----------------------------------------
  256. //Widgets internes
  257. //----------------------------------------
  258. var $config_interface = $('<div />').appendTo($config_content);
  259. $config_interface.css({
  260. "margin-left": '3px',
  261. "font-variant": 'small-caps',
  262. color: '#fff',
  263. height: '100%',
  264. width: '98%',
  265. });
  266. //----------------------------------------
  267. //Configuration du défilement, auto-scroll
  268. //----------------------------------------
  269. var $autoconfig = $('<div />').appendTo($config_interface);
  270. var $autoconfig_title = $('<h2 class="couleur4 configTitre" />').appendTo($autoconfig);
  271. $autoconfig_title.text('Options de défilement du texte');
  272. $autoconfig_title.css({
  273. "margin-bottom": '5px',
  274. "border-bottom": '1px solid',
  275. display: 'block',
  276. "font-size": '17px',
  277. "-webkit-margin-before": '0.83em',
  278. "-webkit-margin-after": '0.83em',
  279. "-webkit-margin-start": '0px',
  280. "-webkit-margin-end": '0px',
  281. "font-weight": 'bold',
  282. position: 'relative',
  283. });
  284. var $autoconfig_container = $('<div class="ligne"/>').appendTo($config_interface);
  285. $autoconfig_container.text('Défilement automatique : ');
  286. $autoconfig_container.css({
  287. display: 'inline-block',
  288. "margin-bottom": '15px',
  289. "margin-left": '5px'
  290. });
  291. var $autoconfig_radio_activate = $('<input type="radio" name="typeAutoRadio" value="false">Activer</input>').appendTo($autoconfig_container);
  292. $autoconfig_radio_activate.css({
  293. margin: '0 5px',
  294. });
  295. $autoconfig_radio_activate.attr('checked', autoScroll);
  296. $autoconfig_radio_activate.change(function(){
  297. autoScroll = true;
  298. GM_setValue("DCCE_autoScroll", autoScroll);
  299. $("#toggleAutoScroll").text("AS on");
  300. });
  301. var $autoconfig_radio_deactivate = $('<input type="radio" name="typeAutoRadio" value="true">Désactiver</input>').appendTo($autoconfig_container);
  302. $autoconfig_radio_deactivate.css({
  303. margin: '0px 5px 0 25px',
  304. "padding-left": '20px',
  305. });
  306. $autoconfig_radio_deactivate.attr('checked', !autoScroll);
  307. $autoconfig_radio_deactivate.change(function(){
  308. autoScroll = false;
  309. GM_setValue("DCCE_autoScroll", autoScroll);
  310. $("#toggleAutoScroll").text("AS off");
  311. });
  312. //----------------------------------------
  313. //Configuration de l'affichage de la barre de défilement
  314. //----------------------------------------
  315. var $scrconfig_container = $('<div class="ligne"/>').appendTo($config_interface);
  316. $scrconfig_container.text('Barre de défilement : ');
  317. $scrconfig_container.css({
  318. display: 'inline-block',
  319. "margin-bottom": '15px',
  320. "margin-left": '5px'
  321. });
  322. var $scrconfig_radio_activate = $('<input type="radio" name="typeScrRadio" value="false">Afficher</input>').appendTo($scrconfig_container);
  323. $scrconfig_radio_activate.css({
  324. margin: '0 5px',
  325. });
  326. $scrconfig_radio_activate.attr('checked', scrollBar);
  327. $scrconfig_radio_activate.change(function(){
  328. scrollBar = true;
  329. GM_setValue("DCCE_scrollBar", scrollBar);
  330. setChatContentScroll();
  331. });
  332. var $scrconfig_radio_deactivate = $('<input type="radio" name="typeScrRadio" value="true">Masquer</input>').appendTo($scrconfig_container);
  333. $scrconfig_radio_deactivate.css({
  334. margin: '0px 5px 0 25px',
  335. "padding-left": '20px',
  336. });
  337. $scrconfig_radio_deactivate.attr('checked', !scrollBar);
  338. $scrconfig_radio_deactivate.change(function(){
  339. scrollBar = false;
  340. GM_setValue("DCCE_scrollBar", scrollBar);
  341. setChatContentScroll();
  342. });
  343. //----------------------------------------
  344. //Configuration de l'affichage de la barre de défilement
  345. //----------------------------------------
  346. var $predconfig_container = $('<div class="ligne"/>').appendTo($config_interface);
  347. $predconfig_container.text('Défiler le chat à l\'écriture : ');
  348. $predconfig_container.css({
  349. display: 'inline-block',
  350. "margin-bottom": '15px',
  351. "margin-left": '5px'
  352. });
  353. var $predconfig_radio_activate = $('<input type="radio" name="typePredRadio" value="false">Oui</input>').appendTo($predconfig_container);
  354. $predconfig_radio_activate.css({
  355. margin: '0 5px',
  356. });
  357. $predconfig_radio_activate.attr('checked', typePredict);
  358. $predconfig_radio_activate.change(function(){
  359. typePredict = true;
  360. GM_setValue("DCCE_typePredict", typePredict);
  361. });
  362. var $predconfig_radio_deactivate = $('<input type="radio" name="typePredRadio" value="true">Non</input>').appendTo($predconfig_container);
  363. $predconfig_radio_deactivate.css({
  364. margin: '0px 5px 0 25px',
  365. "padding-left": '20px',
  366. });
  367. $predconfig_radio_deactivate.attr('checked', !typePredict);
  368. $predconfig_radio_deactivate.change(function(){
  369. typePredict = false;
  370. GM_setValue("DCCE_typePredict", typePredict);
  371. });
  372.  
  373. //----------------------------------------
  374. //Configuration de l'audio joué avec AlertChat
  375. //----------------------------------------
  376. var $audioconfig_container = $('<div class="ligne"/>').appendTo($config_interface);
  377. $audioconfig_container.text('');
  378. $audioconfig_container.css({
  379. display: 'inline-block',
  380. "margin-bottom": '15px',
  381. });
  382. var $audioconfig_pzonechat = $('<div> </div><div>Audio joué à la réception d\'un message (indiquer URL de l\'audio) : </div>').appendTo($audioconfig_container);
  383. $audioconfig_pzonechat.css({
  384. margin: '0 5px',
  385. width: '500px'
  386. });
  387. var $audioconfig_zonechat = $('<input type="url" name="typealertchat" value="' + alertChatAudioURL + '" style="background-color: antiquewhite;"></input>').appendTo($audioconfig_container);
  388. $audioconfig_zonechat.css({
  389. margin: '0 5px',
  390. width: '500px'
  391. });
  392. $audioconfig_zonechat.keyup(function(){
  393. alertChatAudioURL = $(this).val();
  394. if(alertChatAudioURL === "") {
  395. GM_setValue("DCCE_alertChatAudioURL", DEFAULT_ALERT_CHAT_AUDIO_URL);
  396. $('#checkchat').attr('src', DEFAULT_ALERT_CHAT_AUDIO_URL);
  397. } else {
  398. GM_setValue("DCCE_alertChatAudioURL", alertChatAudioURL);
  399. $('#checkchat').attr('src', alertChatAudioURL);
  400. }
  401. });
  402. var $audioconfig_vol = $('<input type="range" name="typealertvolume" value="' + alertVolume + '" min="0" max="1" step="0.01"></input>').appendTo($audioconfig_container);
  403. $audioconfig_vol.css({
  404. margin: '0 5px',
  405. width: '500px'
  406. });
  407. $audioconfig_vol.change(function(){
  408. alertVolume = Number($audioconfig_vol.val());
  409. GM_setValue("DCCE_alertVolume", alertVolume);
  410. document.getElementById('checkchat').volume = (activateAlertChat) ? alertVolume : 0;
  411. });
  412.  
  413.  
  414. this.$window = $config_window;
  415.  
  416.  
  417. //----------------------------------------
  418. //Configuration des couleurs de pseudos dans le chat
  419. //----------------------------------------
  420. var $clrconfig = $('<div />').appendTo($config_interface);
  421. var $clrconfig_title = $('<h2 class="couleur4 configTitre" />').appendTo($clrconfig);
  422. $clrconfig_title.text('Gestion des couleurs de pseudos');
  423. $clrconfig_title.css({
  424. "margin-bottom": '5px',
  425. "border-bottom": '1px solid',
  426. display: 'block',
  427. "font-size": '17px',
  428. "-webkit-margin-before": '0.83em',
  429. "-webkit-margin-after": '0.83em',
  430. "-webkit-margin-start": '0px',
  431. "-webkit-margin-end": '0px',
  432. "font-weight": 'bold',
  433. position: 'relative',
  434. });
  435. var $useritems_table = $('<table id="dcce_colorItems_config"/>').appendTo($clrconfig);
  436. $useritems_table.css({
  437. width: '100%',
  438. border: 'solid 1px white',
  439. margin: '5px 0',
  440. "font-size": '15px',
  441. });
  442. //Ligne d'en-têtes
  443. $useritems_table.append($('<thead><tr><th>Personnage</th><th>Couleur</th><th></th></tr></thead>'));
  444. var $useritems_tbody = $('<tbody />').appendTo($useritems_table);
  445. var localValues = GM_listValues();
  446. for (let j = 0; j < localValues.length; j++) {
  447. if(localValues[j].includes("dcce_ctb_")) {
  448. var type_id = localValues[j];
  449. var $row = $('<tr />').appendTo($useritems_tbody);
  450. $row.addClass("loaded_item");
  451. $row.attr('id', type_id);
  452. var item_perso = GM_getValue("dcce_name_" + localValues[j].slice(9));
  453. var $perso_td = $('<td class="perso_td" style="text-align:left;width:60%;font-size: 20px;padding-left: 5px;">' + item_perso + '</td>').appendTo($row);
  454. var item_couleur = '<input class="dcce_colortagbox" type="color" id="' + localValues[j] + '" value="' + GM_getValue(localValues[j]) + '"/>';
  455. var $couleur_td = $('<td class="couleur_td" style="/*padding-left:10px;*/width:20%;text-align:center">' + item_couleur + '</td>').appendTo($row);
  456. $couleur_td.data('type_ID', type_id);
  457. //Ajout d'un bouton pour la suppression
  458. var $last_td = $('<td style="width:20%"/>').appendTo($row);
  459. var $itemdel_btn = $('<div class="btnTxt" />').appendTo($last_td);
  460. $itemdel_btn.data('type_ID', type_id);
  461. $itemdel_btn.text('Reset');
  462. $itemdel_btn.css({
  463. height: '15px',
  464. margin: '5px 15px',
  465. });
  466. //Handler clic sur le bouton "Supprimer" d'une ligne du tableau
  467. $itemdel_btn.click(function () {
  468. if ($(this).data('confirmed')) {
  469. //Suppression des valeurs de la ligne
  470. var type_id = $(this).data('type_ID');
  471. GM_deleteValue("dcce_ctb_" + type_id.slice(9));
  472. chatChangeColor(type_id);
  473. $(this).parent().parent().children().children("input").val(DEFAULT_CHAT_COLOR); //Reset du color picker
  474. //Remise à zéro du bouton
  475. $(this).text('Reset');
  476. $(this).data('confirmed', false);
  477. } else {
  478. //Besoin d'un second clic, pour confirmation
  479. $(this).text('Confirmer');
  480. $(this).data('confirmed', true);
  481. }
  482. });
  483. $itemdel_btn.mouseleave(function () {
  484. //Annulation de la confirmation de suppression
  485. $(this).text('Reset');
  486. $(this).data('confirmed', false);
  487. });
  488. $couleur_td.children("input").change(function() {
  489. GM_setValue($couleur_td.data('type_ID'), $(this).val());
  490. chatChangeColor($couleur_td.data('type_ID').slice(9));
  491. });
  492. }
  493. }
  494.  
  495. //Css des éléments du tableau
  496. $useritems_table.find('td').css({
  497. border: '1px solid white',
  498. height: '15px'
  499. });
  500.  
  501.  
  502. //----------------------------------------
  503. //Configuration de MatriceRP
  504. //----------------------------------------
  505. var $mrpconfig = $('<div />').appendTo($config_interface);
  506. var $mrpconfig_title = $('<h2 class="couleur4 configTitre" />').appendTo($clrconfig);
  507. $mrpconfig_title.text('Gestion des commandes');
  508. $mrpconfig_title.css({
  509. "margin-bottom": '5px',
  510. "border-bottom": '1px solid',
  511. display: 'block',
  512. "font-size": '17px',
  513. "-webkit-margin-before": '0.83em',
  514. "-webkit-margin-after": '0.83em',
  515. "-webkit-margin-start": '0px',
  516. "-webkit-margin-end": '0px',
  517. "font-weight": 'bold',
  518. position: 'relative',
  519. });
  520. var $commands_table = $('<table id="dcce_commands_config"/>').appendTo($clrconfig);
  521. $commands_table.css({
  522. width: '100%',
  523. border: 'solid 1px white',
  524. margin: '5px 0',
  525. "font-size": '15px',
  526. });
  527.  
  528.  
  529.  
  530. //Ligne d'en-têtes
  531. $commands_table.append($('<thead><tr><th>Alias</th><th>Nom</th><th>Couleur</th><th>Gras</th><th>Action</th></tr></thead>'));
  532. var $commands_tbody = $('<tbody />').appendTo($commands_table);
  533. var cmdTotal = 0;
  534.  
  535. function updateCommand(id) {
  536. //console.log("Update on line: " + id);
  537. mrpCommands[id].alias = $("#mrp_alias_input_" + id).val();
  538. mrpCommands[id].name = $("#mrp_name_input_" + id).val();
  539. mrpCommands[id].color = $("#mrp_color_input_" + id).val();
  540. mrpCommands[id].bold = $("#mrp_bold_input_" + id).attr("checked") == "checked" ? true : false;
  541. mrpCommands[id].rp = $("#mrp_rp_input_" + id).attr("checked") == "checked" ? true : false;
  542. //console.log(mrpCommands[id]);
  543. GM_setValue("DCCE_MRP", JSON.stringify(mrpCommands));
  544. }
  545.  
  546. //Fonction pour générer une ligne au tableau
  547. //cmd {alias:"str", name:"str", color:"#008000", bold:false, rp:true}
  548. function drawCommand(cmd, id) {
  549. let $row = $('<tr id="cmd_row_' + id + '"/>').appendTo($commands_tbody);
  550. $row.addClass("loaded_item");
  551.  
  552. let $alias_td = $('<td class="alias_td" style="text-align:left;font-size: 20px;padding-left: 5px;"><input style="background-color: antiquewhite" type="text" id="mrp_alias_input_' + id + '" value="' + cmd.alias + '"/></td>').appendTo($row);
  553. let $name_td = $('<td class="name_td" style="text-align:left;font-size: 20px;padding-left: 5px;"><input style="background-color: antiquewhite" type="text" id="mrp_name_input_' + id + '" value="' + cmd.name + '"/></td>').appendTo($row);
  554. let $color_td = $('<td class="color_td" style="text-align:center;font-size: 20px;"><input type="color" id="mrp_color_input_' + id + '" value="' + cmd.color + '"/></td>').appendTo($row);
  555. let $bold_td = $('<td class="bold_td" style="text-align:center;font-size: 20px;"><input type="checkbox" id="mrp_bold_input_' + id + '"' + (cmd.bold ? ' checked' : '') + '/></td>').appendTo($row);
  556. let $rp_td = $('<td class="rp_td" style="text-align:center;font-size: 20px;"><input type="checkbox" id="mrp_rp_input_' + id + '"' + (cmd.rp ? ' checked' : '') + '/></td>').appendTo($row);
  557.  
  558. $alias_td.children("input").keyup(function(){updateCommand(id)});
  559. $name_td.children("input").keyup(function(){updateCommand(id)});
  560. $color_td.children("input").change(function(){updateCommand(id)});
  561. $bold_td.children("input").change(function(){updateCommand(id)});
  562. $rp_td.children("input").change(function(){updateCommand(id)});
  563. }
  564.  
  565. for (let j = 0; j < mrpCommands.length; j++) {
  566. $commands_tbody.append(drawCommand(mrpCommands[j], j));
  567. }
  568.  
  569. var $mrp_container = $('<div style="text-align: center"></div>').appendTo($clrconfig);
  570. var $mrp_remove = $('<input style="color: red; background-color: antiquewhite; width: 45%; margin: 5px" type="button" id="mrp_remove" value="Supprimer une ligne" />').click(function(){
  571. if (mrpCommands.length > 3) {
  572. mrpCommands.pop();
  573. GM_setValue("DCCE_MRP", JSON.stringify(mrpCommands));
  574. $("#cmd_row_" + mrpCommands.length).remove();
  575. }
  576. }).appendTo($mrp_container);
  577.  
  578. var $mrp_add = $('<input style="color: green; background-color: antiquewhite; width: 45%; margin: 5px" type="button" id="mrp_add" value="Ajouter une ligne" />').click(function(){
  579. drawCommand({alias:"", name:"", color:"#FFFFFF", bold:false, rp:false}, mrpCommands.length);
  580. stylizeTableCells();
  581. mrpCommands.push({alias:"", name:"", color:"#FFFFFF", bold:false, rp:false});
  582. GM_setValue("DCCE_MRP", JSON.stringify(mrpCommands));
  583. }).appendTo($mrp_container);
  584.  
  585. //Css des éléments du tableau
  586. function stylizeTableCells() {
  587. $commands_table.find('td').css({
  588. border: '1px solid white',
  589. height: '15px'
  590. });
  591. }
  592. stylizeTableCells();
  593. }
  594. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  595. //FIN Constructeur de fenêtre de configuration
  596. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  597.  
  598.  
  599. //---------------------------------------------------
  600. //Ajout d'un item au menu bandeau "Paramètres" de DC
  601. //---------------------------------------------------
  602. var $params_menu = $('.menus > .parametres > ul');
  603. var $dcce_config = $('<li />').appendTo($params_menu);
  604. $dcce_config.text("Configuration du Chat");
  605. $dcce_config.addClass('link couleur2 separator');
  606.  
  607. $dcce_config.click(function () {
  608. //Fermeture des autres instances de paramétrage ouvertes
  609. engine.closeDataBox('dcce_configwindow');
  610. var $config_window = new DCCE_ConfigurationWindow();
  611. $databox.append($config_window.$window);
  612. });
  613.  
  614. //**********************************************
  615. // FIN INTERFACE DE CONFIGURATION UTILISATEUR
  616. //**********************************************
  617.  
  618. //**********************************************
  619. // DEBUT MAIN
  620. //**********************************************
  621.  
  622. //Compte les charactères façon DreadCast: 7 bits = 1 char, 8-11 bits = 2 chars, 12-16 bits = 3 chars
  623. function chatCharCount(str) {
  624. if (!str) return 0;
  625. return str.split("").map(a => a.charCodeAt(0).toString(2).length >= 12 ? 3 : a.charCodeAt(0).toString(2).length >= 8 ? 2 : 1).reduce((a, b) => a + b);
  626. }
  627.  
  628. //ALERTCHAT, Script d'Odul
  629. (function() {
  630. var imgUnmute = 'url(https://i.imgur.com/uvIB44X.png)';
  631. var imgMute = 'url(https://i.imgur.com/8oV9IrJ.png)';
  632.  
  633. var audio = document.createElement('audio');
  634. audio.id='checkchat';
  635. document.body.appendChild(audio);
  636. $('#checkchat').attr('src', alertChatAudioURL);
  637. $("#checkchat").css("display","none");
  638.  
  639. $('<li class="separator"></li>').prependTo($('#bandeau ul.menus'));
  640. var End = $('<li>').prependTo($('#bandeau ul.menus'));
  641. End.attr("id", 'endAudiocheckchat');
  642. End.css({
  643. left: '5px',
  644. height: '30px',
  645. "z-index": '999999',
  646. "background-size": '29px 15px',
  647. "background-repeat": 'no-repeat',
  648. "background-position-y": '4px',
  649. color: '#999'
  650. });
  651. End.text("AC").addClass('link');
  652. End.hover(
  653. function(){
  654. $(this).css("color", "#0073d5");
  655. },
  656. function(){
  657. var colorAC = (activateAlertChat) ? "#999" : "#D00000";
  658. $(this).css("color", colorAC);
  659. }
  660. );
  661. End.click(function() {
  662. activateAlertChat = (activateAlertChat) ? false : true;
  663. GM_setValue("DCCE_activateAlertChat", activateAlertChat);
  664. document.getElementById('endAudiocheckchat').style.backgroundImage = (activateAlertChat) ? imgUnmute : imgMute;
  665. document.getElementById('checkchat').volume = (activateAlertChat) ? alertVolume : 0;
  666. var colorAC = (activateAlertChat) ? "#999" : "#D00000";
  667. End.css("color", colorAC);
  668. });
  669.  
  670. //Initialisation depuis le stockage local
  671. document.getElementById('endAudiocheckchat').style.backgroundImage = (activateAlertChat) ? imgUnmute : imgMute;
  672. document.getElementById('checkchat').volume = (activateAlertChat) ? alertVolume : 0;
  673. var colorAC = (activateAlertChat) ? "#999" : "#D00000";
  674. End.css("color", colorAC);
  675. })();
  676.  
  677.  
  678.  
  679. //MatriceRP
  680. //Par Isilin
  681.  
  682. const FORBIDDEN_ALIASES = ["me", "y", "ye", "yme", "w", "we", "wme", "roll", ""];
  683.  
  684. function tagMessage(inputStr) {
  685.  
  686. let message = inputStr;
  687.  
  688. let aliasUsed = inputStr.split(" ")[0].substr(1);
  689.  
  690. if (message[0] !== "/") return message; //Vérifier avant tout que l'utilisateur veut rentrer une commande...
  691.  
  692. if (FORBIDDEN_ALIASES.indexOf(aliasUsed) > -1) return message; //On ne modifie pas le message si l'alias utilisé est une commande du jeu ou un alias invalide
  693.  
  694. let command = mrpCommands.find(cmd => cmd.alias.toLowerCase() === aliasUsed.toLowerCase()); //On récupère les paramètres de la commande à partir de son alias (vérification non sensible à la casse)
  695.  
  696. if (command === undefined) return message; //On ne modifie pas le message si l'alias utilisé n'est pas défini
  697.  
  698. if (message.length <= command.alias.length + 2) return ""; //On vide le message si un alias est utilisé seul ou avec un espace sans texte
  699.  
  700. message = (command.rp ? "/me " : "")
  701. //+ "[b][c=" + command.color.substr(1) + "]{" + command.name + "}[/c][/b]"
  702. + "[b]{" + command.name + "}[/b]"
  703. + (command.bold ? "[b]" : "")
  704. + "[c=" + command.color.substr(1) + "]" + message.substr(command.alias.length + 1) + "[/c]"
  705. + (command.bold ? "[/b]" : "");
  706.  
  707. return message;
  708. }
  709.  
  710.  
  711.  
  712. //AmeliorationTchat2.0
  713. //Par Odul
  714. var $chatInput = $("#chatForm .text_chat");
  715.  
  716. function beautifyMessage(inputStr) {
  717.  
  718. let message = inputStr;
  719.  
  720. if (/^\/me/i.test(message)) {
  721. message = "/me" + message.substr(3); //Transforme /Me en /me pour que la casse soit respectée et que le chat ressorte bien une emote.
  722. message = message.replace(/"([^\"]+)"/gi, "[c=FFFFFF]$1[/c]");
  723. } else {
  724. message = message.replace(/\*([^\*]+)\*/gi, "[c=58DCF9][i]$1[/i][/c]");
  725. }
  726. return message;
  727. }
  728.  
  729. //Override honteux du code de base de DC
  730. MenuChat.prototype.send = function() {
  731. if (nav.getChat().kw("chatForm")) {
  732. if ("" == $("#chatForm input.text_chat").val())
  733. return !1;
  734. this.checkConversation();
  735. if ($("#chatForm input.text_chat").val().split("").map(a => a.charCodeAt(0).toString(2).length >= 12 ? 3 : a.charCodeAt(0).toString(2).length >= 8 ? 2 : 1).reduce((a, b) => a + b) >= (0 == this.currentMode ? 199 : 195)) return !1; //La seule chose ajoutée par l'override: refuser d'envoyer le message si trop long! :)
  736. 1 == this.currentMode ? $("#chatForm input.text_chat").val("/we " + $("#chatForm input.text_chat").val()) : 2 == this.currentMode && $("#chatForm input.text_chat").val("/ye " + $("#chatForm input.text_chat").val());
  737. engine.submitForm("Menu/Chat/default=Send&etat=2&room=" + this.getRoom(!0), "chatForm", this.update, !0),
  738. 6 == evolution.currentPoint && evolution.unlock(3)
  739. }
  740. }
  741.  
  742.  
  743. //Applique les scripts AmeliorationTchat2.0 et MatriceRP au moment de poster le message
  744. var isMessageLocked = false;
  745. function ameliorInput() {
  746. if (!isMessageLocked) {
  747. isMessageLocked = true;
  748.  
  749. let ogMessage = $chatInput.val(); //Message avant modifications
  750. let finalMessage = tagMessage(beautifyMessage(ogMessage)); //Message balisé, prêt à envoyer
  751. $chatInput.val(finalMessage);
  752.  
  753. //Si le message était trop long pour être envoyé, on attend le refus de la fonction overridée, puis on débalise le message
  754. let ml = $("#chatForm > .text_mode").text() == "N" ? 199 : 195;
  755. if (chatCharCount(finalMessage) >= ml) {
  756. setTimeout(function(){
  757. $chatInput.val(ogMessage);
  758. isMessageLocked = false;
  759. }, 2);
  760. } else {
  761. setTimeout(function(){ isMessageLocked = false; }, 2);
  762. }
  763. }
  764. }
  765.  
  766. function verifyKeyPressed(e) {
  767. if (e.keyCode==13) {
  768. ameliorInput();
  769. }
  770. }
  771.  
  772. $("#chatForm .text_chat").keypress(verifyKeyPressed);
  773. $("#chatForm .text_valider").click(ameliorInput);
  774.  
  775.  
  776. //HIGHLIGHT CHAT LIMIT
  777. //Code de Ladoria, modifications de débugging et implémentation au script.
  778. function HighlightChatLimit() {
  779.  
  780. var limitColor = 'red', //Couleurs pour chaque pallier de longueur
  781. alertColor = 'orange',
  782. warningColor = 'yellow',
  783. limitLength = 199, //Palliers de longueur
  784. alertLength = 170,
  785. warningLength = 135;
  786.  
  787. var c1 = $("#chatForm").css('border-color'); //CSS original de la box
  788. var c2 = $("#chatForm .text_mode").css('border-color');
  789. var c3 = $("#chatForm .text_valider").css('background-color');
  790. var c4 = $("#chatForm").css('box-shadow');
  791.  
  792. var animateChatInput = function(e) {
  793. var processedInput = tagMessage(beautifyMessage($("#chatForm .text_chat").val()));
  794. var len = chatCharCount(processedInput);
  795. let maxLength = $("#chatForm > .text_mode").text() == "N" ? 199 : 195; //Longueur max = 199, sauf si le chat est en mode chuchotement ou cri
  796. if (len >= maxLength) {
  797. highlight(limitColor); // limit reached
  798. $("#chatForm .text_chat").attr("maxlength", $("#chatForm .text_chat").val().length); //On bloque pour que le joueur arrête d'écrire
  799. }
  800. else if (len >= alertLength) {
  801. highlight(alertColor); // approach limit
  802. $("#chatForm .text_chat").attr("maxlength", maxLength);
  803. }
  804. else if (len >= warningLength) {
  805. highlight(warningColor); // first warning
  806. $("#chatForm .text_chat").attr("maxlength", maxLength);
  807. }
  808. else {
  809. originalHighlight(c1, c2, c3, c4); // far away from limit
  810. $("#chatForm .text_chat").attr("maxlength", maxLength);
  811. }
  812. };
  813.  
  814. function originalHighlight(formBorderColor, modeBorderColor, bgColor, bsSettings) {
  815. $("#chatForm").css('border-color', formBorderColor);
  816. $("#chatForm .text_mode").css('border-color', modeBorderColor);
  817. $("#chatForm .text_valider").css('background-color', bgColor);
  818.  
  819. $("#chatForm").css('box-shadow', bsSettings);
  820. }
  821.  
  822. function highlight(color) {
  823. originalHighlight(color, color, color, '0px 0px 3px 2px ' + color);
  824. }
  825.  
  826. $("#chatForm .text_chat").attr("maxlength", "199");
  827. $("#chatForm .text_chat").keyup(animateChatInput);
  828. $("#chatForm > .text_mode").click(animateChatInput);
  829.  
  830. }
  831. HighlightChatLimit(); //Exécution du script de limite de chat.
  832.  
  833.  
  834. //SCROLLING
  835. scrollChat(); //Place le chat au chargement du jeu.
  836. $newMessageAlert.click(scrollChat); //Scroll au clic du bouton d'alerte de nouveau message.
  837. $(".text_chat").keydown(function(key){ //Si en préférence, scroller le chat automatiquement quand on commence à écrire.
  838. if(typePredict && key != 13) scrollChat(); //Ne pas le faire avec la touche entrée car déjà fait quand la ligne apparaît dans le chat.
  839. });
  840. var lastChat = $('#chatContent').text(); //Sert à comparer pour voir si le chat a changé.
  841. setInterval(function(){ //Scrolle ou alerte à la réception d'un message.
  842. if(lastChat != $('#chatContent').text()) {
  843. lastChat = $('#chatContent').text(); //Actualiser la copie local du chat.
  844.  
  845. document.getElementById('checkchat').play();
  846.  
  847. if(autoScroll) {
  848. scrollChat();
  849. }
  850. else if($("#chatContent .link.linkable:last").text() !== $("#txt_pseudo").text()) {
  851. $newMessageAlert.stop().fadeIn(500); //Afficher uniquement le bouton si l'utilisateur ne vient pas de poster.
  852. }
  853. }
  854. }, 1000);
  855.  
  856. //COLOR TAG
  857. $(document).on("click", "span.perso.link", function(){
  858. var idPerso = $(this).attr('id').slice(9);
  859. $(document).one("ajaxSuccess", {idPerso: idPerso}, function(e, xhr, settings){ //Permet d'attendre le chargement de la fenêtre, one() pour éviter un duplicata.
  860. console.log(xhr);
  861. console.log(settings);
  862. var idctb = '#colorTagBox_' + e.data.idPerso;
  863. var colorTagBox = $('<div style="margin-top: 15px; text-align: center;">' + 'Couleur chat: ' +
  864. '<input type="color" id="' + idctb.slice(1) + '" value="' + DEFAULT_CHAT_COLOR + '"/>' +
  865. '<input type="button" id="' + idctb.slice(1) + '_reset" value="Reset" style="background-color: buttonface; margin-left: 5px; height: 16px; font-size: 12px;"/>' +
  866. '</div>').appendTo($("#ib_persoBox_" + e.data.idPerso + " #char_inspect_faketooltip .content"));
  867.  
  868. GM_setValue("dcce_name_" + e.data.idPerso, $("#ib_persoBox_" + e.data.idPerso + " .titreinfo").contents().filter(function(){
  869. return this.nodeType == 3;
  870. })[0].nodeValue); //Récupère le nom du personnage, utilisé dans le nommage de la classe du pseudo.
  871.  
  872. if(GM_getValue("dcce_ctb_" + e.data.idPerso) !== undefined) { //Récupère et applique au bouton couleur la couleur enregistrée
  873. $(idctb).val((GM_getValue("dcce_ctb_" + e.data.idPerso)));
  874. }
  875. $(idctb).on("change", {idPerso: e.data.idPerso}, function(e) { //Enregistre en mémoire la nouvelle couleur
  876. GM_setValue("dcce_ctb_" + e.data.idPerso, $(this).val());
  877. chatChangeColor(e.data.idPerso);
  878. });
  879. $(idctb + "_reset").on("click", {idPerso: e.data.idPerso}, function(e) { //Reset de la couleur
  880. GM_deleteValue("dcce_ctb_" + e.data.idPerso);
  881. $(idctb).val(DEFAULT_CHAT_COLOR);
  882. chatChangeColor(e.data.idPerso);
  883. });
  884. });
  885.  
  886. });
  887.  
  888. //OVERWRITE pour que seul DCCE gère le scroll du chat
  889. MenuChat.prototype.update = function(a) {
  890. if (!xml_result(a))
  891. return !1;
  892. if ($(a).find("cydive").length)
  893. return cydiving.readChat(a),
  894. !0;
  895. $(a).find("chat").each(function() {
  896. if ($(this).attr("key"))
  897. $("#" + $(this).attr("key")).html($(this).xml());
  898. else {
  899. var a = $.trim($(this).find("#chatContent").xml());
  900. if (a && ($("#zone_droite #zone_chat #chatContent, #chat_preview .chatContent").append(a),
  901. //$("#chatContent").scrollTop(jQuery("#chatContent").innerHeight()), //RETRAIT DE CETTE LIGNE
  902. Tutoriel.instance.tutoData.actif && !Tutoriel.instance.isTutoCompleted(Tutoriel.EVENT_CHAT) && $(this).find("span.link.linkable").length)) {
  903. var b = $(this).find("span.link.linkable").attr("alt");
  904. engine.getIdPersonnage() != b && $(window).trigger(Tutoriel.EVENT_CHAT)
  905. }
  906. }
  907. }),
  908. $(a).find("connectes").length && $("#zone_chat .connectes").html($(a).find("connectes").xml());
  909. $("#zone_chat").height(),
  910. $("#zone_chat .connectes").height(),
  911. $("#zone_chat .chatForm").height(),
  912. $("#zone_chat").height(),
  913. $("#zone_chat .chatForm").height();
  914. $(a).find("chat").attr("time") && nav.getChat().setTimeCurrentRoom($(a).find("chat").attr("time")),
  915. $("#zone_chat .loader").hide()
  916. }
  917.  
  918. console.log("DCCE activé.");
  919. });