HighlightChatLimit

Script for Dreadcast. Features : Light up text input chat when limit's reached and do some funky stuff around it.

  1. // ==UserScript==
  2. // @name HighlightChatLimit
  3. // @namespace InGame
  4. // @author Ladoria
  5. // @date 20/03/2014
  6. // @version 1.4
  7. // @description Script for Dreadcast. Features : Light up text input chat when limit's reached and do some funky stuff around it.
  8. // @license WTF Public License; http://en.wikipedia.org/wiki/WTF_Public_License
  9. // @include http://www.dreadcast.net/Main
  10. // @compat Chrome
  11. // ==/UserScript==
  12.  
  13. var fullySecond = false; // true if text already at size limit
  14.  
  15. // Params [FR]
  16. var fastCompletion = false; // [Âme de beta testeur? (Ahah) Testes les points de suspension. Remplacer 'false' par 'true'], true to enable auto replacing cuted work by '...'
  17. var alertLenght = 20 // [Nombre de caractère restant pour lever l'alerte]
  18. var alertColor = 'orange'; // [Couleur de l'effet pour l'approche de la limite]
  19. var limitColor = 'red'; // [Couleur de l'effet à l'atteinte de la limite]
  20.  
  21. var animateChatInput = function(e) {
  22. var textChatLimit = 140;
  23. var endingPattern = /[\Sa-zA-Z0-9]*[\s|\.]*$/gi; // find a word or spaces or '...'
  24. // limit reached
  25. if ($("#chatForm .text_chat").val().length >= textChatLimit) {
  26. // add '...' command -> reduce text while it's too large
  27. if(fastCompletion && fullySecond) {
  28. do {
  29. $("#chatForm .text_chat").val($("#chatForm .text_chat").val().replace(endingPattern, '') + '...');
  30. }
  31. while ($("#chatForm .text_chat").val().length > textChatLimit);
  32. alertHighlight();
  33. fullySecond = false;
  34. return;
  35. }
  36. limitHighlight();
  37. fullySecond = true;
  38. return;
  39. }
  40. // approach limit
  41. if ($("#chatForm .text_chat").val().length >= textChatLimit - alertLenght) {
  42. alertHighlight();
  43. return;
  44. }
  45. // far away from limit
  46. originalHighlight();
  47. }
  48.  
  49. function limitHighlight() {
  50. var nsc1 = '0px 0px 3px 2px ';
  51.  
  52. $("#chatForm").css('border-color',limitColor);
  53. $("#chatForm .text_mode").css('border-color',limitColor);
  54. $("#chatForm .text_valider").css('background-color',limitColor);
  55. $("#chatForm").css('box-shadow',nsc1 + limitColor);
  56. }
  57.  
  58. function alertHighlight() {
  59. var nsc2 = '0px 0px 3px 2px ';
  60.  
  61. $("#chatForm").css('border-color',alertColor);
  62. $("#chatForm .text_mode").css('border-color',alertColor);
  63. $("#chatForm .text_valider").css('background-color',alertColor);
  64. $("#chatForm").css('box-shadow',nsc2 + alertColor);
  65. }
  66.  
  67. var c1 = $("#chatForm").css('border-color');
  68. var c2 = $("#chatForm .text_mode").css('border-color');
  69. var c3 = $("#chatForm .text_valider").css('background-color');
  70. var c4 = $("#chatForm").css('box-shadow');
  71.  
  72. function originalHighlight() {
  73. $("#chatForm").css('border-color',c1);
  74. $("#chatForm .text_mode").css('border-color',c2);
  75. $("#chatForm .text_valider").css('background-color',c3);
  76. $("#chatForm").css('box-shadow',c4);
  77. }
  78.  
  79. document.addEventListener('keyup', animateChatInput, false);