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