Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. function decodeHtml(html) {
  2. var txt = document.createElement("textarea");
  3. txt.innerHTML = html;
  4. return txt.value;
  5. }
  6.  
  7. function encodeHtml(str) {
  8. var div = document.createElement('div');
  9. div.appendChild(document.createTextNode(str));
  10. return div.innerHTML;
  11. }
  12.  
  13. function usergroup_id_to_class_name(group_id) {
  14. if (parseInt(group_id) == 99) {
  15. return 'chatBot';
  16. }
  17. return 'usergroup-' + group_id;
  18. }
  19.  
  20. (function(window, document, options, undefined) {
  21. var lang = {
  22. 'en': {
  23. 'logged_in': 'You are now logged in as [username]',
  24. 'conn_closed_label': 'Your connection is <strong>closed</strong>, please <strong>refresh</strong>',
  25. 'rate_limiting_error': 'Error:\nWe have received too many messages from your IP and we\'ve banned it for the next [seconds] seconds\nYour last message has NOT been sent.',
  26. 'rate_limiting_warning': 'Warning:\nWe have received too many messages from your IP and we will ban it for the next [seconds] seconds.\nPlease, write fewer messages to avoid bothering our other users.'
  27. },
  28.  
  29. 'de': {
  30. /* TODO */
  31. }
  32. }[options.lang_code];
  33.  
  34. var shout = document.getElementById(options.shout_id),
  35. chats = shout.children[0],
  36. form = shout.children[1];
  37.  
  38. chats.removeChild(chats.children[0]);
  39. if (window.WebSocket === undefined) {
  40. return;
  41. }
  42. chats.removeChild(chats.children[0]);
  43.  
  44. var Set = function() {};
  45. Set.prototype.add = function(o) { this[o] = true; };
  46. Set.prototype.remove = function(o) { delete this[o]; };
  47.  
  48. var mouseover_timeout = 0,
  49. appendMessage = function(epoch, user_id, username, group_id, raw_content, autoscroll) {
  50. var must_scroll = autoscroll && chats.scrollTop == (chats.scrollHeight - chats.offsetHeight);
  51.  
  52. var local_date = new Date(0);
  53. local_date.setUTCSeconds(epoch);
  54.  
  55. var count = chats.childElementCount,
  56. p = document.createElement('p'),
  57. a = document.createElement('a'),
  58. name = document.createTextNode(username),
  59. d = document.createElement('span');
  60.  
  61. // Format the username
  62. a.setAttribute('href', 'profile.php?id=' + parseInt(user_id));
  63. a.setAttribute('target', '_blank');
  64. a.className = usergroup_id_to_class_name(group_id);
  65. a.appendChild(name);
  66.  
  67. // Format date
  68. d.textContent = '[' + local_date.toLocaleTimeString() + '] ';
  69. d.className = 'dateTime';
  70.  
  71. // Format the message
  72. p.textContent = ': ' + decodeHtml(raw_content);
  73.  
  74. // Create links
  75. p.innerHTML = anchorme(p.innerHTML, {
  76. attributes:[
  77. {
  78. name: "target",
  79. value: "_blank"
  80. }
  81. ]});
  82.  
  83. p.insertBefore(a, p.firstChild);
  84. p.insertBefore(d, p.firstChild);
  85.  
  86. if ((count % 2) == 0) {
  87. p.className = 'rowEven';
  88. } else {
  89. p.className = 'rowOdd';
  90. }
  91.  
  92. chats.appendChild(p);
  93.  
  94. if(must_scroll) {
  95. chats.scrollTop = chats.scrollHeight;
  96. }
  97. };
  98.  
  99. var chat_input = document.getElementById('shouttext');
  100.  
  101. var conn_closed_label = document.createElement('label');
  102. conn_closed_label.appendChild(document.createElement('span'));
  103. conn_closed_label.children[0].innerHTML = lang['conn_closed_label'];
  104.  
  105. chat_input.onkeydown = checkEnter;
  106. chat_input.onchange = fixMessage;
  107. chat_input.style.visibility = 'visible';
  108. chat_input.disabled = false;
  109.  
  110. // Show emoji selector
  111. var emoji_selector = document.getElementById("emojiselector");
  112. var emoji_count = emoji.length;
  113.  
  114. function addEmoji(code) {
  115. var option = document.createElement('option');
  116. option.innerHTML = code;
  117. emoji_selector.appendChild(option);
  118. }
  119.  
  120. for (var index = 0; index < emoji_count; index++) {
  121. addEmoji(emoji[index]);
  122. }
  123.  
  124. var addEmojiToInput = function () {
  125. chat_input.value += emoji_selector.value;
  126. chat_input.focus();
  127. };
  128.  
  129. emoji_selector.onchange = addEmojiToInput;
  130.  
  131. return false;
  132. }
  133.  
  134. )(
  135. this,
  136. this.document,
  137. {
  138. lang_code: 'en',
  139. shout_id: 'shout',
  140. websocket_url: 'wss://gamesense.pub/forums/shoutbox/'
  141. }
  142. );
  143.  
  144. var seconds = Math.round((new Date()).getTime() / 1000);
  145. appendMessage(seconds, 2, 'admin', 1, encodeHtml('apolo gay'), true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement