Bloble.io NoobScript V3 ChatCommands Fragment

A fragment of code from NoobScript V3 - Chat commands.

目前为 2018-11-12 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Bloble.io NoobScript V3 ChatCommands Fragment
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description A fragment of code from NoobScript V3 - Chat commands.
  6. // @author NoobishHacker
  7. // @match http://bloble.io/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. window.UIList = window.UIList || [];
  12. window.initFuncs = window.initFuncs || [];
  13. window.statusItems = window.statusItems || [];
  14. window.overrideSocketEvents = window.overrideSocketEvents || [];
  15.  
  16. window.chatCommands = window.chatCommands || {};
  17.  
  18. window.resetCamera = function () { // Override
  19. camX = camXS = camY = camYS = 0;
  20. cameraKeys = {
  21. l: 0,
  22. r: 0,
  23. u: 0,
  24. d: 0
  25. }
  26.  
  27. if (socket && window.overrideSocketEvents && window.overrideSocketEvents.length) {
  28. window.overrideSocketEvents.forEach((item) => {
  29. socket.removeAllListeners(item.name)
  30. socket.on(item.name, item.func);
  31.  
  32. });
  33.  
  34. }
  35. }
  36.  
  37. var muted = [];
  38. window.overrideSocketEvents.push({
  39. name: "ch",
  40. description: "Chat Muter",
  41. func: function (a, d, c) {
  42. if (!muted[a])
  43. addChatLine(a, d, c)
  44. }
  45.  
  46. })
  47.  
  48. window.addChat = function (msg, from, color) {
  49. color = color || "#fff";
  50. var b = document.createElement("li");
  51. b.className = "chatother";
  52. b.innerHTML = '<span style="color:' + color + '">[' + from + ']</span> <span class="chatText">' + msg + "</span>";
  53. 10 < chatList.childNodes.length && chatList.removeChild(chatList.childNodes[0]);
  54. chatList.appendChild(b)
  55. }
  56.  
  57.  
  58. window.chatCommands.mute = function (split) {
  59. if (!split[1]) {
  60. addChat('Please specify a username or "all" for 1rst arg.')
  61. } else if (split[1] === 'all') {
  62. users.forEach((user) => {
  63. muted[user.sid] = true;
  64. });
  65. addChat('Muted ' + users.length + ' users', 'Client');
  66.  
  67. } else {
  68. var len = 0;
  69. users.forEach((user) => {
  70. if (user.name === split[1]) {
  71. muted[user.sid] = true;
  72. len++;
  73. }
  74.  
  75. });
  76. addChat('Muted ' + len + ' users with the name ' + split[1], 'Client');
  77. }
  78. }
  79. window.chatCommands.unmute = function (split) {
  80. if (!split[1]) {
  81. addChat('Please specify a username or "all" for 1rst arg.')
  82. } else if (split[1] === 'all') {
  83. addChat('Unmuted ' + Object.keys(mute).length + ' users', 'Client');
  84. muted = {};
  85. } else {
  86. var len = 0;
  87. users.forEach((user) => {
  88. if (user.name === split[1]) {
  89. muted[user.sid] = false;
  90. len++;
  91. }
  92. });
  93. addChat('Unmuted ' + len + ' users with the name ' + split[1], 'Client');
  94. }
  95. }
  96. window.chatCommands.help = function (split) {
  97. var avail = Object.keys(window.chatCommands);
  98. addChat('There are ' + avail.length + ' commands available.', 'Client')
  99. addChat(avail.join(', '), 'Client');
  100. }
  101.  
  102. window.chatCommands.playerlist = function (split) {
  103. var page = parseInt(split[1]) || 1;
  104. var total = Math.ceil(users.length / 5);
  105. addChat('There are ' + users.length + ' players. Page ' + page + ' out of ' + total, 'Client')
  106. var offset = page * 5;
  107. for (var i = 0; i < 5; i++) {
  108. if (!users[i + offset]) break;
  109. addChat(users[i + offset].name, 'Client', playerColors[users[i + offset].color])
  110. }
  111. }
  112.  
  113.  
  114. window.chatCommands.clear = function () {
  115. while (chatList.hasChildNodes()) {
  116. chatList.removeChild(chatList.lastChild);
  117. }
  118. }
  119. var modsShown = true;
  120. window.chatCommands.toggle = function () {
  121. var element = document.getElementById('noobscriptUI')
  122. if (modsShown) {
  123. modsShown = false;
  124. element.style.display = 'none';
  125. addChat('Mod Menu disabled', 'Client')
  126. } else {
  127. modsShown = true;
  128. element.style.display = 'block';
  129. addChat('Mod Menu enabled', 'Client')
  130. }
  131. }
  132.  
  133. var chatHist = [];
  134. var chatHistInd = -1;
  135. var prevText = '';
  136.  
  137.  
  138.  
  139. setTimeout(function () {
  140. var old = chatInput
  141. chatInput = old.cloneNode(true);
  142. old.parentNode.replaceChild(chatInput, old);
  143. chatInput.onclick = function () {
  144. toggleChat(!0)
  145. };
  146.  
  147. chatInput.addEventListener("keyup", function (a) {
  148. var b = a.which || a.keyCode;
  149. if (b === 38) { // up
  150. if (chatHistInd === -1) {
  151. prevText = chatInput.value;
  152. chatHistInd = chatHist.length;
  153. }
  154. if (chatHistInd > 0) chatHistInd--;
  155. chatInput.value = prevText + (chatHist[chatHistInd] || '')
  156.  
  157. } else if (b === 40) {
  158. if (chatHistInd !== -1) {
  159.  
  160. if (chatHistInd < chatHist.length) chatHistInd++;
  161. else chatHistInd = -1;
  162. chatInput.value = prevText + (chatHist[chatHistInd] || '')
  163. }
  164. } else
  165. if (gameState && socket && 13 === (a.which || a.keyCode) && "" != chatInput.value) {
  166. var value = chatInput.value;
  167. chatInput.value = ""
  168. mainCanvas.focus()
  169. if (value.charAt(0) === '/') {
  170.  
  171. var split = value.split(' ');
  172. var name = split[0].substr(1);
  173. if (window.chatCommands[name]) window.chatCommands[name](split);
  174. else {
  175. addChat("Command '" + name + "' not found. Please do /help for a list of commands.")
  176. }
  177. } else {
  178. socket.emit("ch", value)
  179. }
  180. if (chatHist[chatHist.length - 1] !== value) {
  181. var ind = chatHist.indexOf(value);
  182. if (ind !== -1) {
  183. chatHist.splice(ind, 1);
  184. }
  185. chatHist.push(value);
  186. }
  187. chatHistInd = -1;
  188. }
  189. })
  190. },1000)
  191.