Advertisement
DayDun

Untitled

Mar 4th, 2017
2,951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. function createCoolNinjaSpyChatPanel() {
  2. function listenToMessage(id, message) {
  3. if (typeof message == "object") {
  4. var messageHTML = document.createElement("span");
  5. messageHTML.className = "noDrag";
  6. messageHTML.style.display = "block";
  7. messageHTML.innerHTML = message.message;
  8. messages.appendChild(messageHTML);
  9. messageBuilder.scrollToBottom(messages);
  10. if (message.raw.toLowerCase().indexOf(Attributes.get("nick").toLowerCase())) {
  11. audioPlayer.name.play();
  12. } else {
  13. audioPlayer.chat.play();
  14. }
  15. }
  16. }
  17.  
  18. var panel = document.createElement("div");
  19. panel.className = "noDrag";
  20. panel.style.display = "flex";
  21. panel.style.flexDirection = "column";
  22. panel.style.position = "absolute";
  23. panel.style.top = "0px";
  24. panel.style.left = "0px";
  25. panel.style.width = "400px";
  26. panel.style.height = "200px";
  27. panel.style.resize = "both";
  28. panel.style.overflow = "auto";
  29. panel.style.backgroundColor = "#111";
  30. panel.style.border = "1px solid #888";
  31.  
  32. var header = document.createElement("div");
  33. header.style.flex = "0 0 auto";
  34. header.style.padding = "4px";
  35. header.style.cursor = "pointer";
  36. header.style.color = "#000";
  37. header.style.fontWeight = "bold";
  38. header.style.backgroundColor = "#ccc";
  39. var title = document.createElement("span");
  40. title.innerHTML = "Cool Ninja Spy Chat";
  41. var closeButton = document.createElement("span");
  42. closeButton.style.float = "right";
  43. closeButton.style.marginRight = "5px";
  44. closeButton.innerHTML = "x";
  45. closeButton.addEventListener("click", function() {
  46. document.body.removeChild(panel);
  47. socket.removeEventListener("typing", listenToMessage);
  48. });
  49. header.appendChild(title);
  50. header.appendChild(closeButton);
  51. panel.appendChild(header);
  52.  
  53. var content = document.createElement("div");
  54. content.className = "noDrag";
  55. content.style.flex = "1 1 auto";
  56. content.style.display = "flex";
  57. content.style.flexDirection = "column";
  58.  
  59. var messages = document.createElement("div");
  60. messages.className = "noDrag";
  61. messages.style.flex = "1 1 auto";
  62. messages.style.color = "#222";
  63. messages.style.backgroundColor = "#fff";
  64. messages.style.whiteSpace = "pre-wrap";
  65. messages.style.fontFamily = "Consolas, Lucida Console, Courier New, monospace";
  66. messages.style.overflow = "auto";
  67.  
  68. var inputBar = document.createElement("div");
  69. inputBar.className = "noDrag";
  70. inputBar.style.flex = "0 0 auto";
  71. inputBar.style.width = "100%";
  72. inputBar.style.boxSizing = "border-box";
  73. inputBar.style.padding = "5px";
  74. inputBar.style.backgroundColor = "#ccc";
  75.  
  76. var input = document.createElement("textarea");
  77. input.className = "noDrag";
  78. input.style.width = "calc(100% - 10px)";
  79. input.style.height = "17px";
  80. input.style.backgroundColor = "#eee";
  81. input.style.color = "#000";
  82. input.style.fontFamily = "Consolas, Lucida Console, Courier New, monospace";
  83. input.style.fontSize = "14px";
  84. input.style.boxShadow = "rgba(255, 255, 255, 0.0980392) 0px 1px 0px, rgba(0, 0, 0, 0.8) 0px 1px 7px 0px inset";
  85. input.style.padding = "4px 3px";
  86. input.style.border = "1px solid #111";
  87. input.style.borderRadius = "5px";
  88. input.style.outline = "none";
  89. input.style.resize = "none";
  90. input.placeholder = "Type your darkest secrets here";
  91.  
  92. var history = [],
  93. historyIndex = 0;
  94.  
  95. input.addEventListener("keydown", function(event) {
  96. switch(event.which) {
  97. case 13:
  98. if (!event.shiftKey) {
  99. event.preventDefault();
  100. if (this.value) {
  101. historyIndex = 0;
  102. history.unshift(this.value);
  103. socket.emit("typing", {
  104. message: "<b>[" + new Date().format("mediumTime") + "] " +
  105. Attributes.get("nick") + ":</b> " + this.value,
  106. raw: this.value
  107. });
  108. this.value = "";
  109. }
  110. }
  111. break;
  112. case 38:
  113. if (event.shiftKey && historyIndex < history.length) {
  114. historyIndex++;
  115. this.value = history[historyIndex];
  116. }
  117. break;
  118. case 40:
  119. if (event.shiftKey && historyIndex >= 1) {
  120. historyIndex--;
  121. this.value = history[historyIndex];
  122. }
  123. break;
  124. }
  125. if (historyIndex === 0) {
  126. history[0] = this.value;
  127. }
  128. });
  129. input.addEventListener("input", function(event) {
  130. this.style.height = 0;
  131. this.style.height = Math.min(this.scrollHeight - 8, 18 * 6) + "px";
  132. });
  133.  
  134. inputBar.appendChild(input);
  135. content.appendChild(messages);
  136. content.appendChild(inputBar);
  137. panel.appendChild(content);
  138.  
  139. $$$.draggable(panel, "noDrag");
  140.  
  141. document.body.appendChild(panel);
  142.  
  143. socket.on("typing", listenToMessage);
  144. }
  145.  
  146. createCoolNinjaSpyChatPanel();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement