Dreadcast Chat Enhancer

Améliore le chat de Dreadcast.

当前为 2017-06-17 提交的版本,查看 最新版本

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