Kongregate Textbox Extender

Enlarges texbox areas when writing PMs, shouts, your About Me section, and when replying to messages. Simply double-click to toggle normal/extended textbox. Custom length available in User Script Commands.

  1. // ==UserScript==
  2. // @name Kongregate Textbox Extender
  3. // @namespace http://matthewammann.com
  4. // @description Enlarges texbox areas when writing PMs, shouts, your About Me section, and when replying to messages. Simply double-click to toggle normal/extended textbox. Custom length available in User Script Commands.
  5. // @include http://www.kongregate.com/accounts/*
  6. // @exclude http://www.kongregate.com/accounts/*/monitored
  7. // @author Matthew Ammann
  8. // @version 1.1
  9. // @date 01/11/12
  10. // ==/UserScript==
  11.  
  12. var mainShoutBox = document.getElementById("shout_content")
  13. var path = location.pathname;
  14. var pathArray = path.split("/");
  15. var isWhisperPage = new Boolean(false);
  16. var isShoutPage = new Boolean(false);
  17. var firstClick = new Boolean(true);
  18. var messagesArray;
  19.  
  20. GM_registerMenuCommand("Input Extended Texbox Length", inputPrompt)
  21. var extendedLength = GM_getValue("textboxLength", "300px");
  22.  
  23. if(!parseInt(extendedLength, 10))
  24. extendedLength = "300px";
  25.  
  26. function inputPrompt()
  27. {
  28. var input = prompt("Please enter the the desired texbox length (in pixels) as a number. The default extended length is 300.");
  29. var parsedInput = parseInt(input, 10);
  30. if(!parsedInput)
  31. input = "300";
  32. input = String(input + "px");
  33. extendedLength = input;
  34. GM_setValue("textboxLength", input);
  35. }
  36.  
  37. if(mainShoutBox)
  38. {
  39. addEvent(mainShoutBox);
  40. mainShoutBox.addEventListener("blur", blurHandler, false);
  41. }
  42.  
  43. if(pathArray[3])
  44. {
  45. if(pathArray[3] == "private_messages")
  46. {
  47. isWhisperPage = true;
  48. messagesArray = document.getElementsByClassName("whisper user_message");
  49. traverseMessages();
  50. }
  51. else if(pathArray[3] == "messages")
  52. {
  53. isShoutPage = true;
  54. messagesArray = document.getElementsByClassName("shout user_message");
  55. traverseMessages();
  56. }
  57. else if(pathArray[3] == "edit_profile")
  58. {
  59. var aboutMe = document.getElementById("user_about");
  60. aboutMe.addEventListener("dblclick", function(){toggleExpand(aboutMe)}, false);
  61. }
  62. }
  63. else if(pathArray[1] == "accounts")
  64. {
  65. messagesArray = document.getElementsByClassName("shout user_message");
  66. if(messagesArray)
  67. traverseMessages();
  68. }
  69. function traverseMessages()
  70. {
  71. for(i=0; i < messagesArray.length; i++)
  72. {
  73. var messageComments = messagesArray[i].getElementsByClassName("message_reply_container")[0].getElementsByClassName("message_comments")[0];
  74. var replyTextbox = messageComments.getElementsByTagName("textarea")[0]
  75. addEvent(replyTextbox);
  76. }
  77. }
  78.  
  79. function addEvent(element)
  80. {
  81. if(firstClick)
  82. element.addEventListener("focus", function(){focusHandler(element)}, false);
  83.  
  84. element.addEventListener("dblclick", function(){toggleExpand(element)}, false);
  85. }
  86.  
  87. function focusHandler(element)
  88. {
  89. firstClick = false;
  90. if(element.value.length == 0)
  91. element.style.setProperty("height", "auto" , "important");
  92.  
  93. element.removeEventListener("focus", function(){focusHandler(element)}, false);
  94. }
  95.  
  96. function toggleExpand(element)
  97. {
  98. if(element.id == "shout_content")
  99. {
  100. if(element.style.height == "24px" || element.style.height == extendedLength || firstClick == true)
  101. element.style.setProperty("height", "auto" , "important");
  102. else
  103. element.style.setProperty("height", extendedLength , "important");
  104. firstClick = false;
  105. }
  106. else if(element.id == "user_about")
  107. {
  108. element.cols = "62"
  109. element.style.setProperty("height", extendedLength , "important");
  110. }
  111. else if(element.style.height == "55px" || element.style.height == "" || element.style.height == "auto")
  112. element.style.setProperty("height", extendedLength , "important");
  113.  
  114. else
  115. element.style.setProperty("height", "55px" , "important");
  116.  
  117. element.addEventListener("blur", blurHandler, false);
  118. element.focus();
  119. }
  120.  
  121. function blurHandler()
  122. {
  123. if(this.value.length == 0)
  124. {
  125. if(this.id == "shout_content")
  126. this.style.setProperty("height", "24px" , "important");
  127. else
  128. this.style.setProperty("height", "15px" , "important");
  129. }
  130. firstClick = true;
  131. }