Dreadcast Chat Enhancer

Améliore le chat de Dreadcast.

当前为 2017-01-28 提交的版本,查看 最新版本

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