Dreadcast Chat Enhancer

Améliore le chat de Dreadcast.

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

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