Dreadcast Chat Enhancer

Améliore le chat de Dreadcast.

当前为 2016-07-31 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Dreadcast Chat Enhancer
  3. // @namespace https://greasyfork.org/scripts/21359-dreadcast-chat-enhancer/
  4. // @version 2.1.1
  5. // @description Améliore le chat de Dreadcast.
  6. // @author MockingJay, Odul, Ladoria
  7. // @match http://www.dreadcast.net/Main
  8. // @grant GM_setValue
  9. // @grant GM_getValue
  10. // @grant GM_deleteValue
  11. // @grant GM_listValues
  12. // ==/UserScript==
  13.  
  14. //Lit les variables dans GM à la demande. A utiliser pour chaque déclaration de variable qui est copiée en mémoire.
  15. //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.
  16. function initLocalMemory(defaultValue, localVarName) {
  17. if (GM_getValue(localVarName) === undefined) {
  18. GM_setValue(localVarName, defaultValue);
  19. return defaultValue;
  20. } else {
  21. return GM_getValue(localVarName);
  22. }
  23. }
  24.  
  25. function rgb2hex(orig){
  26. var rgb = orig.replace(/\s/g,'').match(/^rgba?\((\d+),(\d+),(\d+)/i);
  27. return (rgb && rgb.length === 4) ? "#" +
  28. ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
  29. ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
  30. ("0" + parseInt(rgb[3],10).toString(16)).slice(-2) : orig;
  31. }
  32.  
  33. $(document).ready(function() {
  34.  
  35. //**********************************************
  36. // DECLARATION DES VARIABLES
  37. //**********************************************
  38.  
  39. //CONSTANTES
  40. var W_ZONE_CHAT = 317; //Largeur de base des différents éléments du chat.
  41. var W_MSG = 290;
  42. var W_CHATCONTENT = 308; //Valeur pas d'origine, mais nécessaire pour le script.
  43. var W_CHAT = 328;
  44. var W_ONGLETS_CHAT = 254;
  45. var W_CHATFORM = 288;
  46.  
  47. var DEFAULT_CHAT_COLOR = rgb2hex($("#zone_chat .zone_infos").css("color"));
  48. var DEFAULT_CHAT_COLOR5 = ($(".couleur5").css("color") !== undefined) ? rgb2hex($(".couleur5").css("color")) : "#999";
  49. var DEFAULT_CHAT_COLOR_RED = ($(".couleur_rouge").css("color") !== undefined) ? rgb2hex($(".couleur_rouge").css("color")) : "#D32929";
  50.  
  51. var 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.
  52. var DEFAULT_SCRIPT_ZONE_DROITE_BG = 'http://i.imgur.com/kPzRqS2.png';
  53. var DEFAULT_SCRIPT_ZONE_CHAT_BG = 'http://i.imgur.com/0J3wOK0.png';
  54.  
  55. var DEFAULT_ALERT_CHAT_AUDIO_URL = 'http://www.universal-soundbank.com/802a/805020000000000000000000000pkjn800000000000000000000000000000090/g/85055050505050505050505/k/4030.MP3';
  56.  
  57. //Initialisation variables de préférences
  58. var autoScroll = initLocalMemory(false, "DCCE_autoScroll");
  59. var scrollBar = initLocalMemory(true, "DCCE_scrollBar");
  60. var typePredict = initLocalMemory(true, "DCCE_typePredict");
  61. var chatExtend = initLocalMemory(0, "DCCE_chatExtend");
  62.  
  63. var scriptZoneDroiteBG = initLocalMemory(DEFAULT_SCRIPT_ZONE_DROITE_BG, "DCCE_scriptZoneDroiteBG");
  64. var scriptZoneChatBG = initLocalMemory(DEFAULT_SCRIPT_ZONE_CHAT_BG, "DCCE_scriptZoneChatBG");
  65.  
  66. var alertChatAudioURL = initLocalMemory(DEFAULT_ALERT_CHAT_AUDIO_URL, "DCCE_alertChatAudioURL");
  67. var activateAlertChat = initLocalMemory(false, "DCCE_activateAlertChat");
  68.  
  69. var chatWidthStyle = $('<style id="chatWidthStyle">').appendTo("head"); //Utilisation d'une règle CSS car objets créés dynamiquement.
  70.  
  71. 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.
  72. var chatEmoteStyleWe = $('<style id="chatEmoteStyleWe">.msg.couleur5 span[style*="color:#58DCF9;"] em{color: ' + DEFAULT_CHAT_COLOR5 + ';}</style>').appendTo("head");
  73. var chatEmoteStyleYe = $('<style id="chatEmoteStyleYe">.msg.couleur_rouge span[style*="color:#58DCF9;"] em{color: ' + DEFAULT_CHAT_COLOR_RED + ';}</style>').appendTo("head");
  74. var chatEmoteStyleSpeech = $('<style id="chatEmoteStyleSpeech">.msg em span[style*="color:#FFFFFF;"]{font-style: normal;}</style>').appendTo("head"); //Redresse les paroles dans des emotes
  75. //Un non-utilisateur du script aura la couleur de base bleu clair.
  76.  
  77. //**********************************************
  78. // DECLARATION DES FONCTIONS, MISE EN PLACE DU CSS
  79. //**********************************************
  80.  
  81. $("#chatContent").css({
  82. "overflow-x": 'hidden',
  83. "overflow-y": 'scroll',
  84. height: '313px', //width traitée dans setChatCSS
  85. });
  86.  
  87. //Applique la barre de défilement en fonction des préférences, et règle la largeur des lignes dans le chat.
  88. function setChatContentScroll() {
  89. if(scrollBar) {
  90. $("#chatContent").css({"padding-right": '0px'});
  91. chatWidthStyle.text('#zone_chat .zone_infos .msg{width:' + (W_MSG + chatExtend) + 'px}');
  92. $("#zone_chat").css({width: (W_ZONE_CHAT + 5 + chatExtend) + 'px'}); //Assure d'avoir le fond derrière la scrollbar lorsque le chat est étendu.
  93. }
  94. else {
  95. $("#chatContent").css({"padding-right": '15px'});
  96. chatWidthStyle.text('#zone_chat .zone_infos .msg{width:' + (W_MSG + 7 + chatExtend) + 'px}');
  97. $("#zone_chat").css({width: (W_ZONE_CHAT + chatExtend) + 'px'});
  98. }
  99. }
  100.  
  101.  
  102. var $dcce_background = $('<div id="dcce_background"></div>').prependTo($("#zone_page")).css({left: '907px', top: '142px', height: '461px'});
  103.  
  104. function setZoneChatBackground() {
  105. if(chatExtend > 0) {
  106. $dcce_background.css({background: 'url("' + scriptZoneChatBG + '")',
  107. "background-size": '100% 100%',
  108. width: (W_ZONE_CHAT + 13 + chatExtend) + 'px'});
  109. $("#zone_droite").css({background: 'url("' + scriptZoneDroiteBG + '")'});
  110. } else {
  111. $dcce_background.css({background: 'none'});
  112. $("#zone_droite").css({background: DEFAULT_ZONE_DROITE_BG});
  113. }
  114. }
  115.  
  116. function setChatCSS() {
  117. setChatContentScroll(); //Comprend déjà #ZONE_CHAT et .MSG
  118. setZoneChatBackground();
  119. //Fixer les largeurs restantes
  120. $("#chatContent").width(W_CHATCONTENT + chatExtend);
  121. $("#zone_chat .zone_infos .chat").width(W_CHAT + chatExtend);
  122. $("#zone_chat #onglets_chat").width(W_ONGLETS_CHAT + chatExtend);
  123. $("#chatForm").width(W_CHATFORM + chatExtend);
  124. }
  125.  
  126. setChatCSS(); //Appliquer à l'initialisation.
  127.  
  128. //Initialisation du bouton d'alerte, utilisé quand l'autoScroll est désactivé.
  129. var $newMessageAlert = $('<div />').appendTo($('#zone_chat'));
  130. $newMessageAlert.text("⚠ Nouveau message! ⚠");
  131. $newMessageAlert.css({
  132. display: 'none',
  133. top: '45px',
  134. "text-align": 'center',
  135. cursor: 'pointer',
  136. background: '#fff',
  137. border: '1px solid #fff',
  138. color: '#0296bb',
  139. "margin-top": '2px',
  140. "-webkit-box-shadow": '0 0 4px 2px #329bc2',
  141. });
  142. $newMessageAlert.attr('onmouseover', 'this.style.backgroundColor=\"#0b9bcb\";this.style.color=\"#FFFFFF\";');
  143. $newMessageAlert.attr('onmouseout', 'this.style.backgroundColor=\"#FFFFFF\";this.style.color=\"#0296bb\";');
  144.  
  145. //Initialisation bandeau latéral
  146. var $toggleAutoScroll = $('<li id="toggleAutoScroll" class="couleur5" ></li>'+'<li class="separator"></li>').prependTo($('#bandeau ul.menus'));
  147. if(autoScroll) {
  148. $("#toggleAutoScroll").text("AS on");
  149. } else {
  150. $("#toggleAutoScroll").text("AS off");
  151. }
  152. $("#toggleAutoScroll").css({
  153. cursor: 'pointer',
  154. });
  155. $("#toggleAutoScroll").attr('onmouseover', 'this.style.color=\"#0073d5\";');
  156. $("#toggleAutoScroll").attr('onmouseout', 'this.style.color=\"#999\";');
  157. //Changer l'autoscroll au clic sur le bandeau latéral.
  158. $("#toggleAutoScroll").click(function(){
  159. if(autoScroll) {
  160. autoScroll = false;
  161. $("#toggleAutoScroll").text("AS off");
  162. } else {
  163. autoScroll = true;
  164. $("#toggleAutoScroll").text("AS on");
  165. }
  166. GM_setValue("DCCE_autoScroll", autoScroll);
  167. });
  168.  
  169. //Fait défiler le chat jusqu'en bas.
  170. function scrollChat(){
  171. $('#chatContent').stop().animate({
  172. scrollTop: $('#chatContent')[0].scrollHeight
  173. }, 800);
  174. $newMessageAlert.stop().fadeOut(500);
  175. }
  176.  
  177. var colorTagStyle = $('<style id="colorTagStyle">').appendTo("head"); //Utilisation d'une règle CSS car objets créés dynamiquement.
  178.  
  179. function chatChangeColor(id) {
  180. var persoName = GM_getValue("dcce_name_" + id);
  181. var colorRule = GM_getValue("dcce_ctb_" + id);
  182. if (colorRule === undefined) colorRule = DEFAULT_CHAT_COLOR;
  183.  
  184. var newRule = '.c' + persoName + '{color: '+ colorRule +';}\n';
  185. colorTagStyle.text(colorTagStyle.text() + newRule);
  186.  
  187. }
  188.  
  189. function initChatColor() {
  190. var localValues = GM_listValues();
  191. for(var i = 0; i < localValues.length; i++) {
  192. if(localValues[i].includes("dcce_ctb_")) {
  193. chatChangeColor(localValues[i].slice(9));
  194. }
  195. }
  196. }
  197. initChatColor();
  198.  
  199. var chatCouleur5Important = $('<style id="chatCouleur5Important">.couleur5 span.link.linkable{color: #999 !important;}</style>').appendTo("head"); //Forcer la couleur grise sur les messages chuchotés.
  200.  
  201. //**********************************************
  202. //INTERFACE DE CONFIGURATION UTILISATEUR
  203. //**********************************************
  204. var $databox = $('#zone_dataBox');
  205. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  206. //Constructeur de fenêtre de configuration
  207. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  208. var DCCE_ConfigurationWindow = function () {
  209. var window_width = '560px';
  210. var window_height = '450px';
  211. var $config_window = $('<div id="dcce_configwindow" onclick="engine.switchDataBox(this)"/>');
  212. $config_window.draggable();
  213. $config_window.addClass('dataBox focused ui-draggable');
  214. $config_window.css({
  215. width: window_width,
  216. "margin-left": '-185px',
  217. display: 'block',
  218. position: 'absolute',
  219. "z-index": '2',
  220. });
  221. for (var i = 1; i <= 8; i++) {
  222. $('<div class="dbfond' + i + '" />').appendTo($config_window);
  223. }
  224. var $config_head = $('<div class="head ui-draggable-handle" ondblclick="$(\'#dcce_configwindow\').toggleClass(\'reduced\');" />').appendTo($config_window);
  225. $('<div title="Fermer la fenêtre (Q)" class="info1 link close" onclick="engine.closeDataBox($(this).parent().parent().attr(\'id\'));" />').appendTo($config_head);
  226. $('<div title="Reduire/Agrandir la fenêtre" class="info1 link reduce" onclick="$(\'#dcce_configwindow\').toggleClass(\'reduced\');" />').appendTo($config_head);
  227. $('<div class="title">Configuration DC Enhanced Chat</div>').appendTo($config_head);
  228. $('<div class="dbloader" />').appendTo($config_window);
  229. var $config_content = $('<div class="content" style="height:' + window_height + '; overflow: auto"/>').appendTo($config_window);
  230. //----------------------------------------
  231. //Widgets internes
  232. //----------------------------------------
  233. var $config_interface = $('<div />').appendTo($config_content);
  234. $config_interface.css({
  235. "margin-left": '3px',
  236. "font-variant": 'small-caps',
  237. color: '#fff',
  238. height: '100%',
  239. width: '98%',
  240. });
  241. //----------------------------------------
  242. //Configuration du défilement, auto-scroll
  243. //----------------------------------------
  244. var $autoconfig = $('<div />').appendTo($config_interface);
  245. var $autoconfig_title = $('<h2 class="couleur4 configTitre" />').appendTo($autoconfig);
  246. $autoconfig_title.text('Options de défilement du texte');
  247. $autoconfig_title.css({
  248. "margin-bottom": '5px',
  249. "border-bottom": '1px solid',
  250. display: 'block',
  251. "font-size": '17px',
  252. "-webkit-margin-before": '0.83em',
  253. "-webkit-margin-after": '0.83em',
  254. "-webkit-margin-start": '0px',
  255. "-webkit-margin-end": '0px',
  256. "font-weight": 'bold',
  257. position: 'relative',
  258. });
  259. var $autoconfig_container = $('<div class="ligne"/>').appendTo($config_interface);
  260. $autoconfig_container.text('Défilement automatique : ');
  261. $autoconfig_container.css({
  262. display: 'inline-block',
  263. "margin-bottom": '15px',
  264. "margin-left": '5px'
  265. });
  266. var $autoconfig_radio_activate = $('<input type="radio" name="typeAutoRadio" value="false">Activer</input>').appendTo($autoconfig_container);
  267. $autoconfig_radio_activate.css({
  268. margin: '0 5px',
  269. });
  270. $autoconfig_radio_activate.attr('checked', autoScroll);
  271. $autoconfig_radio_activate.change(function(){
  272. autoScroll = true;
  273. GM_setValue("DCCE_autoScroll", autoScroll);
  274. $("#toggleAutoScroll").text("AS on");
  275. });
  276. var $autoconfig_radio_deactivate = $('<input type="radio" name="typeAutoRadio" value="true">Désactiver</input>').appendTo($autoconfig_container);
  277. $autoconfig_radio_deactivate.css({
  278. margin: '0px 5px 0 25px',
  279. "padding-left": '20px',
  280. });
  281. $autoconfig_radio_deactivate.attr('checked', !autoScroll);
  282. $autoconfig_radio_deactivate.change(function(){
  283. autoScroll = false;
  284. GM_setValue("DCCE_autoScroll", autoScroll);
  285. $("#toggleAutoScroll").text("AS off");
  286. });
  287. //----------------------------------------
  288. //Configuration de l'affichage de la barre de défilement
  289. //----------------------------------------
  290. var $scrconfig_container = $('<div class="ligne"/>').appendTo($config_interface);
  291. $scrconfig_container.text('Barre de défilement : ');
  292. $scrconfig_container.css({
  293. display: 'inline-block',
  294. "margin-bottom": '15px',
  295. "margin-left": '5px'
  296. });
  297. var $scrconfig_radio_activate = $('<input type="radio" name="typeScrRadio" value="false">Afficher</input>').appendTo($scrconfig_container);
  298. $scrconfig_radio_activate.css({
  299. margin: '0 5px',
  300. });
  301. $scrconfig_radio_activate.attr('checked', scrollBar);
  302. $scrconfig_radio_activate.change(function(){
  303. scrollBar = true;
  304. GM_setValue("DCCE_scrollBar", scrollBar);
  305. setChatContentScroll();
  306. });
  307. var $scrconfig_radio_deactivate = $('<input type="radio" name="typeScrRadio" value="true">Masquer</input>').appendTo($scrconfig_container);
  308. $scrconfig_radio_deactivate.css({
  309. margin: '0px 5px 0 25px',
  310. "padding-left": '20px',
  311. });
  312. $scrconfig_radio_deactivate.attr('checked', !scrollBar);
  313. $scrconfig_radio_deactivate.change(function(){
  314. scrollBar = false;
  315. GM_setValue("DCCE_scrollBar", scrollBar);
  316. setChatContentScroll();
  317. });
  318. //----------------------------------------
  319. //Configuration de l'affichage de la barre de défilement
  320. //----------------------------------------
  321. var $predconfig_container = $('<div class="ligne"/>').appendTo($config_interface);
  322. $predconfig_container.text('Défiler le chat à l\'écriture : ');
  323. $predconfig_container.css({
  324. display: 'inline-block',
  325. "margin-bottom": '15px',
  326. "margin-left": '5px'
  327. });
  328. var $predconfig_radio_activate = $('<input type="radio" name="typePredRadio" value="false">Oui</input>').appendTo($predconfig_container);
  329. $predconfig_radio_activate.css({
  330. margin: '0 5px',
  331. });
  332. $predconfig_radio_activate.attr('checked', typePredict);
  333. $predconfig_radio_activate.change(function(){
  334. typePredict = true;
  335. GM_setValue("DCCE_typePredict", typePredict);
  336. });
  337. var $predconfig_radio_deactivate = $('<input type="radio" name="typePredRadio" value="true">Non</input>').appendTo($predconfig_container);
  338. $predconfig_radio_deactivate.css({
  339. margin: '0px 5px 0 25px',
  340. "padding-left": '20px',
  341. });
  342. $predconfig_radio_deactivate.attr('checked', !typePredict);
  343. $predconfig_radio_deactivate.change(function(){
  344. typePredict = false;
  345. GM_setValue("DCCE_typePredict", typePredict);
  346. });
  347.  
  348. //----------------------------------------
  349. //Configuration de l'audio joué avec AlertChat
  350. //----------------------------------------
  351. var $audioconfig_container = $('<div class="ligne"/>').appendTo($config_interface);
  352. $audioconfig_container.text('');
  353. $audioconfig_container.css({
  354. display: 'inline-block',
  355. "margin-bottom": '15px',
  356. });
  357. var $audioconfig_pzonechat = $('<div> </div><div>Audio joué à la réception d\'un message (indiquer URL de l\'audio) : </div>').appendTo($audioconfig_container);
  358. $audioconfig_pzonechat.css({
  359. margin: '0 5px',
  360. width: '500px'
  361. });
  362. var $audioconfig_zonechat = $('<input type="url" name="typealertchat" value="' + alertChatAudioURL + '" style="background-color: antiquewhite;"></input>').appendTo($audioconfig_container);
  363. $audioconfig_zonechat.css({
  364. margin: '0 5px',
  365. width: '500px'
  366. });
  367. $audioconfig_zonechat.keyup(function(){
  368. alertChatAudioURL = $(this).val();
  369. GM_setValue("DCCE_alertChatAudioURL", alertChatAudioURL);
  370. $('#checkchat').attr('src', alertChatAudioURL);
  371. });
  372.  
  373.  
  374. this.$window = $config_window;
  375.  
  376. //----------------------------------------
  377. //Configuration de la largeur du chat
  378. //----------------------------------------
  379. var $xtdconfig = $('<div />').appendTo($config_interface);
  380. var $xtdconfig_title = $('<h2 class="couleur4 configTitre" />').appendTo($xtdconfig);
  381. $xtdconfig_title.text('Largeur du chat');
  382. $xtdconfig_title.css({
  383. "margin-bottom": '5px',
  384. "border-bottom": '1px solid',
  385. display: 'block',
  386. "font-size": '17px',
  387. "-webkit-margin-before": '0.83em',
  388. "-webkit-margin-after": '0.83em',
  389. "-webkit-margin-start": '0px',
  390. "-webkit-margin-end": '0px',
  391. "font-weight": 'bold',
  392. position: 'relative',
  393. });
  394. var $xtdconfig_container = $('<div class="ligne"/>').appendTo($config_interface);
  395. //$xtdconfig_container.text('Défilement automatique : ');
  396. $xtdconfig_container.css({
  397. display: 'inline-block',
  398. "margin-bottom": '15px',
  399. });
  400. var $xtdconfig_range = $('<input type="range" name="typeXtdRange" value="' + chatExtend + '" min="0" max="300" step="1"></input>').appendTo($xtdconfig_container);
  401. $xtdconfig_range.css({
  402. margin: '0 5px',
  403. width: '500px'
  404. });
  405. $xtdconfig_range.change(function(){
  406. chatExtend = Number($xtdconfig_range.val());
  407. GM_setValue("DCCE_chatExtend", chatExtend);
  408. setChatCSS();
  409. });
  410.  
  411. //----------------------------------------
  412. //Configuration des fonds de zone droite/chat customs
  413. //----------------------------------------
  414. var $bgconfig = $('<div />').appendTo($config_interface);
  415. var $bgconfig_title = $('<h2 class="couleur4 configTitre" />').appendTo($bgconfig);
  416. $bgconfig_title.text('Fonds de zone customisés (pour réinitialiser, effacer la ligne)');
  417. $bgconfig_title.css({
  418. "margin-bottom": '5px',
  419. "border-bottom": '1px solid',
  420. display: 'block',
  421. "font-size": '17px',
  422. "-webkit-margin-before": '0.83em',
  423. "-webkit-margin-after": '0.83em',
  424. "-webkit-margin-start": '0px',
  425. "-webkit-margin-end": '0px',
  426. "font-weight": 'bold',
  427. position: 'relative',
  428. });
  429. var $bgconfig_container = $('<div class="ligne"/>').appendTo($config_interface);
  430. $bgconfig_container.css({
  431. display: 'inline-block',
  432. "margin-bottom": '15px',
  433. });
  434. var $bgconfig_pzonedroite = $('<div>Fond messagerie (indiquer URL de l\'image) :</div>').appendTo($bgconfig_container);
  435. $bgconfig_pzonedroite.css({
  436. margin: '0 5px',
  437. width: '500px'
  438. });
  439. var $bgconfig_zonedroite = $('<input type="url" name="typeBGzonedroite" value="' + scriptZoneDroiteBG + '" style="background-color: antiquewhite;"></input>').appendTo($bgconfig_container);
  440. $bgconfig_zonedroite.css({
  441. margin: '0 5px',
  442. width: '500px'
  443. });
  444. $bgconfig_zonedroite.keyup(function(){
  445. if($(this).val() === DEFAULT_SCRIPT_ZONE_DROITE_BG || $(this).val() === "") {
  446. GM_deleteValue("DCCE_scriptZoneDroiteBG");
  447. scriptZoneDroiteBG = DEFAULT_SCRIPT_ZONE_DROITE_BG;
  448. } else {
  449. scriptZoneDroiteBG = $(this).val();
  450. GM_setValue("DCCE_scriptZoneDroiteBG", scriptZoneDroiteBG);
  451. }
  452. setZoneChatBackground();
  453. });
  454. var $bgconfig_pzonechat = $('<div> </div><div>Fond chat (indiquer URL de l\'image) :</div>').appendTo($bgconfig_container);
  455. $bgconfig_pzonechat.css({
  456. margin: '0 5px',
  457. width: '500px'
  458. });
  459. var $bgconfig_zonechat = $('<input type="url" name="typeBGzonechat" value="' + scriptZoneChatBG + '" style="background-color: antiquewhite;"></input>').appendTo($bgconfig_container);
  460. $bgconfig_zonechat.css({
  461. margin: '0 5px',
  462. width: '500px'
  463. });
  464. $bgconfig_zonechat.keyup(function(){
  465. if($(this).val() === DEFAULT_SCRIPT_ZONE_CHAT_BG || $(this).val() === "") {
  466. GM_deleteValue("DCCE_scriptZoneChatBG");
  467. scriptZoneChatBG = DEFAULT_SCRIPT_ZONE_CHAT_BG;
  468. } else {
  469. scriptZoneChatBG = $(this).val();
  470. GM_setValue("DCCE_scriptZoneChatBG", scriptZoneChatBG);
  471. }
  472. setZoneChatBackground();
  473. });
  474.  
  475. //----------------------------------------
  476. //Configuration des couleurs de pseudos dans le chat
  477. //----------------------------------------
  478. var $clrconfig = $('<div />').appendTo($config_interface);
  479. var $clrconfig_title = $('<h2 class="couleur4 configTitre" />').appendTo($clrconfig);
  480. $clrconfig_title.text('Gestion des couleurs de pseudos');
  481. $clrconfig_title.css({
  482. "margin-bottom": '5px',
  483. "border-bottom": '1px solid',
  484. display: 'block',
  485. "font-size": '17px',
  486. "-webkit-margin-before": '0.83em',
  487. "-webkit-margin-after": '0.83em',
  488. "-webkit-margin-start": '0px',
  489. "-webkit-margin-end": '0px',
  490. "font-weight": 'bold',
  491. position: 'relative',
  492. });
  493. var $useritems_table = $('<table id="dcce_colorItems_config"/>').appendTo($clrconfig);
  494. $useritems_table.css({
  495. width: '100%',
  496. border: 'solid 1px white',
  497. margin: '5px 0',
  498. "font-size": '15px',
  499. });
  500. //Ligne d'en-têtes
  501. $useritems_table.append($('<thead><tr><th>Personnage</th><th>Couleur</th><th></th></tr></thead>'));
  502. var $useritems_tbody = $('<tbody />').appendTo($useritems_table);
  503. var localValues = GM_listValues();
  504. for (var j = 0; j < localValues.length; j++) {
  505. if(localValues[j].includes("dcce_ctb_")) {
  506. var type_id = localValues[j];
  507. var $row = $('<tr />').appendTo($useritems_tbody);
  508. $row.addClass("loaded_item");
  509. $row.attr('id', type_id);
  510. var item_perso = GM_getValue("dcce_name_" + localValues[j].slice(9));
  511. var $perso_td = $('<td class="perso_td" style="text-align:left;width:60%;font-size: 20px;padding-left: 5px;">' + item_perso + '</td>').appendTo($row);
  512. var item_couleur = '<input class="dcce_colortagbox" type="color" id="' + localValues[j] + '" value="' + GM_getValue(localValues[j]) + '"/>';
  513. var $couleur_td = $('<td class="couleur_td" style="/*padding-left:10px;*/width:20%;text-align:center">' + item_couleur + '</td>').appendTo($row);
  514. $couleur_td.data('type_ID', type_id);
  515. //Ajout d'un bouton pour la suppression
  516. var $last_td = $('<td style="width:20%"/>').appendTo($row);
  517. var $itemdel_btn = $('<div class="btnTxt" />').appendTo($last_td);
  518. $itemdel_btn.data('type_ID', type_id);
  519. $itemdel_btn.text('Reset');
  520. $itemdel_btn.css({
  521. height: '15px',
  522. margin: '5px 15px',
  523. });
  524. //Handler clic sur le bouton "Supprimer" d'une ligne du tableau
  525. $itemdel_btn.click(function () {
  526. if ($(this).data('confirmed')) {
  527. //Suppression des valeurs de la ligne
  528. var type_id = $(this).data('type_ID');
  529. GM_deleteValue("dcce_ctb_" + type_id.slice(9));
  530. chatChangeColor(type_id);
  531. $(this).parent().parent().children().children("input").val(DEFAULT_CHAT_COLOR); //Reset du color picker
  532. //Remise à zéro du bouton
  533. $(this).text('Reset');
  534. $(this).data('confirmed', false);
  535. } else {
  536. //Besoin d'un second clic, pour confirmation
  537. $(this).text('Confirmer');
  538. $(this).data('confirmed', true);
  539. }
  540. });
  541. $itemdel_btn.mouseleave(function () {
  542. //Annulation de la confirmation de suppression
  543. $(this).text('Reset');
  544. $(this).data('confirmed', false);
  545. });
  546. $couleur_td.children("input").change(function() {
  547. GM_setValue($couleur_td.data('type_ID'), $(this).val());
  548. chatChangeColor($couleur_td.data('type_ID').slice(9));
  549. });
  550. }
  551. }
  552.  
  553. //Css des éléments du tableau
  554. $useritems_table.find('td').css({
  555. border: '1px solid white',
  556. height: '15px'
  557. });
  558. };
  559. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  560. //FIN Constructeur de fenêtre de configuration
  561. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  562.  
  563.  
  564. //---------------------------------------------------
  565. //Ajout d'un item au menu bandeau "Paramètres" de DC
  566. //---------------------------------------------------
  567. var $params_menu = $('.menus > .parametres > ul');
  568. var $dcce_config = $('<li />').appendTo($params_menu);
  569. $dcce_config.text("Configuration du Chat");
  570. $dcce_config.addClass('link couleur2 separator');
  571.  
  572. $dcce_config.click(function () {
  573. //Fermeture des autres instances de paramétrage ouvertes
  574. engine.closeDataBox('dcce_configwindow');
  575. var $config_window = new DCCE_ConfigurationWindow();
  576. $databox.append($config_window.$window);
  577. });
  578.  
  579. //**********************************************
  580. // FIN INTERFACE DE CONFIGURATION UTILISATEUR
  581. //**********************************************
  582.  
  583. //**********************************************
  584. // DEBUT MAIN
  585. //**********************************************
  586.  
  587. //ALERTCHAT, Script d'Odul
  588. (function() {
  589. var imgUnmute = 'url(http://s3.noelshack.com/old/up/unmute-bae5a6d548.png)';
  590. var imgMute = 'url(http://s3.noelshack.com/old/up/mute-5980e7fa83.png)';
  591.  
  592. var audio = document.createElement('audio');
  593. audio.id='checkchat';
  594. document.body.appendChild(audio);
  595. $('#checkchat').attr('src', alertChatAudioURL);
  596. $("#checkchat").css("display","none");
  597.  
  598. $('<li class="separator"></li>').prependTo($('#bandeau ul.menus'));
  599. var End = $('<li>').prependTo($('#bandeau ul.menus'));
  600. End.attr("id", 'endAudiocheckchat');
  601. End.css({
  602. left: '5px',
  603. height: '30px',
  604. "z-index": '999999',
  605. "background-size": '29px 15px',
  606. "background-repeat": 'no-repeat',
  607. "background-position-y": '6px',
  608. color: '#999'
  609. });
  610. End.text("AC").addClass('link');
  611. End.mouseover(function(){this.style.color="#0073d5";}).mouseout(function(){this.style.color="#999";});
  612. End.click(function() {
  613. activateAlertChat = (activateAlertChat) ? false : true;
  614. GM_setValue("DCCE_activateAlertChat", activateAlertChat);
  615. document.getElementById('endAudiocheckchat').style.backgroundImage = (activateAlertChat) ? imgUnmute : imgMute;
  616. document.getElementById('checkchat').volume = (activateAlertChat) ? 1 : 0;
  617. });
  618.  
  619. //Initialisation depuis le stockage local
  620. document.getElementById('endAudiocheckchat').style.backgroundImage = (activateAlertChat) ? imgUnmute : imgMute;
  621. document.getElementById('checkchat').volume = (activateAlertChat) ? 1 : 0;
  622. })();
  623.  
  624.  
  625. //AmeliorationTchat2.0 par Odul
  626. var ameliorInput = function(e) {
  627. if (e.keyCode==13) {
  628. $("#chatForm .text_chat").val($("#chatForm .text_chat").val().replace(/\*([^\*]+)\*/gi, "[couleur=58DCF9][i]$1[/i][/couleur]"));
  629.  
  630. do {
  631. $("#chatForm .text_chat").val($("#chatForm .text_chat").val().replace(/(^\/me.+?)"([^\"]+)"/gi, "$1[couleur=FFFFFF]$2[/couleur]"));
  632. }while (/(^\/me.+?)"([^\"]+)"/i.test($("#chatForm .text_chat").val()));
  633.  
  634. }
  635. };
  636.  
  637. $("#chatForm .text_chat").on('keypress', ameliorInput);
  638.  
  639.  
  640. //HIGHLIGHT CHAT LIMIT
  641. //Code de Ladoria, modifications de débugging et implémentation au script.
  642. function HighlightChatLimit() {
  643.  
  644. var alertLenght = 20;// [Nombre de caractère restant pour lever l'alerte]
  645. var alertColor = 'orange'; // [Couleur de l'effet pour l'approche de la limite]
  646. var limitColor = 'red'; // [Couleur de l'effet à l'atteinte de la limite]
  647. var textChatLimit = 140;
  648.  
  649. var animateChatInput = function(e) {
  650. if ($("#chatForm .text_chat").val().length >= textChatLimit)
  651. limitHighlight(); // limit reached
  652. else if ($("#chatForm .text_chat").val().length >= textChatLimit - alertLenght)
  653. alertHighlight(); // approach limit
  654. else
  655. originalHighlight(); // far away from limit
  656. };
  657.  
  658. function limitHighlight() {
  659. var nsc1 = '0px 0px 3px 2px ';
  660.  
  661. $("#chatForm").css('border-color',limitColor);
  662. $("#chatForm .text_mode").css('border-color',limitColor);
  663. $("#chatForm .text_valider").css('background-color',limitColor);
  664.  
  665. $("#chatForm").css('box-shadow',nsc1 + limitColor);
  666. }
  667.  
  668. function alertHighlight() {
  669. var nsc2 = '0px 0px 3px 2px ';
  670.  
  671. $("#chatForm").css('border-color',alertColor);
  672. $("#chatForm .text_mode").css('border-color',alertColor);
  673. $("#chatForm .text_valider").css('background-color',alertColor);
  674.  
  675. $("#chatForm").css('box-shadow',nsc2 + alertColor);
  676. }
  677.  
  678. var c1 = $("#chatForm").css('border-color');
  679. var c2 = $("#chatForm .text_mode").css('border-color');
  680. var c3 = $("#chatForm .text_valider").css('background-color');
  681. var c4 = $("#chatForm").css('box-shadow');
  682.  
  683. function originalHighlight() {
  684. $("#chatForm").css('border-color',c1);
  685. $("#chatForm .text_mode").css('border-color',c2);
  686. $("#chatForm .text_valider").css('background-color',c3);
  687.  
  688. $("#chatForm").css('box-shadow',c4);
  689. }
  690.  
  691. $("#chatForm .text_chat").attr("maxlength", "200");
  692. $("#chatForm .text_chat").on('keyup', animateChatInput);
  693.  
  694. }
  695. HighlightChatLimit(); //Exécution du script de limite de chat.
  696.  
  697.  
  698. //SCROLLING
  699. scrollChat(); //Place le chat au chargement du jeu.
  700. $newMessageAlert.click(scrollChat); //Scroll au clic du bouton d'alerte de nouveau message.
  701. $(".text_chat").keydown(function(key){ //Si en préférence, scroller le chat automatiquement quand on commence à écrire.
  702. 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.
  703. });
  704. var lastChat = $('#chatContent').text(); //Sert à comparer pour voir si le chat a changé.
  705. setInterval(function(){ //Scrolle ou alerte à la réception d'un message.
  706. if(lastChat != $('#chatContent').text()) {
  707. lastChat = $('#chatContent').text(); //Actualiser la copie local du chat.
  708.  
  709. var audio = document.getElementById('checkchat');
  710. audio.load();
  711. audio.play();
  712.  
  713. if(autoScroll) {
  714. scrollChat();
  715. }
  716. else {
  717. $newMessageAlert.stop().fadeIn(500);
  718. }
  719. }
  720. }, 1000);
  721.  
  722. //COLOR TAG
  723. $(document).on("click", "span.perso.link", function(){
  724. var idPerso = $(this).attr('id').slice(9);
  725. $(document).one("ajaxSuccess", {idPerso: idPerso}, function(e){ //Permet d'attendre le chargement de la fenêtre, one() pour éviter un duplicata.
  726. var idctb = '#colorTagBox_' + e.data.idPerso;
  727. var colorTagBox = $('<div style="margin-top: 15px; text-align: center;">' + 'Couleur chat: ' +
  728. '<input type="color" id="' + idctb.slice(1) + '" value="' + DEFAULT_CHAT_COLOR + '"/>' +
  729. '<input type="button" id="' + idctb.slice(1) + '_reset" value="Reset" style="background-color: buttonface; margin-left: 5px; height: 16px; font-size: 12px;"/>' +
  730. '</div>').appendTo($("#ib_persoBox_" + e.data.idPerso + " .fakeToolTip"));
  731.  
  732. GM_setValue("dcce_name_" + e.data.idPerso, $("#ib_persoBox_" + e.data.idPerso + " .titreinfo").contents().filter(function(){
  733. return this.nodeType == 3;
  734. })[0].nodeValue); //Récupère le nom du personnage, utilisé dans le nommage de la classe du pseudo.
  735.  
  736. if(GM_getValue("dcce_ctb_" + e.data.idPerso) !== undefined) { //Récupère et applique au bouton couleur la couleur enregistrée
  737. $(idctb).val((GM_getValue("dcce_ctb_" + e.data.idPerso)));
  738. }
  739. $(idctb).on("change", {idPerso: e.data.idPerso}, function(e) { //Enregistre en mémoire la nouvelle couleur
  740. GM_setValue("dcce_ctb_" + e.data.idPerso, $(this).val());
  741. chatChangeColor(e.data.idPerso);
  742. });
  743. $(idctb + "_reset").on("click", {idPerso: e.data.idPerso}, function(e) { //Reset de la couleur
  744. GM_deleteValue("dcce_ctb_" + e.data.idPerso);
  745. $(idctb).val(DEFAULT_CHAT_COLOR);
  746. chatChangeColor(e.data.idPerso);
  747. });
  748. });
  749.  
  750. });
  751. });