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