Bloble.io NoobScript V3 GameUtils Fragment

A fragment of code from NoobScript V3 - The FPS and resolution setter.

  1. // ==UserScript==
  2. // @name Bloble.io NoobScript V3 GameUtils Fragment
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description A fragment of code from NoobScript V3 - The FPS and resolution setter.
  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. // Resolution and FPS chooser.
  15. var resolution = 1;
  16. var rate = 0;
  17.  
  18. window.removeEventListener("mousemove", gameInput);
  19.  
  20. window.gameInput = function (a) {
  21. a.preventDefault();
  22. a.stopPropagation();
  23. mouseX = a.clientX * resolution;
  24. mouseY = a.clientY * resolution;
  25. }
  26. window.addEventListener("mousemove", gameInput, false);
  27. window.removeEventListener("resize", resize);
  28. window.resize = function (n) {
  29. screenWidth = window.innerWidth * resolution;
  30. screenHeight = window.innerHeight * resolution;
  31. scaleFillNative = MathMAX(screenWidth / maxScreenWidth, screenHeight / maxScreenHeight);
  32. if (n !== true) {
  33. mainCanvas.width = screenWidth;
  34. mainCanvas.height = screenHeight;
  35. mainCanvas.style.width = (screenWidth / resolution) + "px";
  36. mainCanvas.style.height = (screenHeight / resolution) + "px";
  37. }
  38.  
  39. mainContext.setTransform(scaleFillNative, 0, 0, scaleFillNative, Math.floor((screenWidth - maxScreenWidth * scaleFillNative) / 2), Math.floor((screenHeight - maxScreenHeight * scaleFillNative) / 2));
  40. player || renderBackground()
  41. }
  42. window.addEventListener("resize", resize);
  43. window.statusItems.push({
  44. order: 3,
  45. value: function () {
  46. return document.getElementById('fps').textContent;
  47. }
  48. }, {
  49. order: 4,
  50. name: 'Resolution',
  51. value: function () {
  52. return document.getElementById('res').textContent;
  53. }
  54. });
  55. window.UIList.push({
  56. level: 3,
  57. x: 4,
  58. html: '<div id="res" onclick=setRes()>Normal Res</div>'
  59. }, {
  60. level: 3,
  61. x: 5,
  62. html: '<div id="fps" onclick=setFPS()>Unlim FPS</div>'
  63. }, {
  64. level: 3,
  65. x: 1,
  66. html: '<div id="afk" onclick=afk()>AFK off</div>'
  67. });
  68. var afkinterval = false;
  69. window.afk = function () {
  70. var element = document.getElementById('afk');
  71. if (afkinterval) {
  72. clearInterval(afkinterval)
  73. afkinterval = false;
  74. element.textContent = 'AFK off';
  75. } else {
  76. afkinterval = setInterval(function () {
  77. socket.emit("2", Math.round(camX), Math.round(camY));
  78. }, 1000)
  79. element.textContent = 'AFK on';
  80. }
  81. }
  82. window.setRes = function () {
  83. var el = document.getElementById('res');
  84. if (resolution === 2) {
  85. resolution = .5;
  86. el.textContent = 'Low Res';
  87. } else if (resolution === .5) {
  88. resolution = .8;
  89. el.textContent = 'Med Res';
  90. } else if (resolution === .8) {
  91. resolution = 1;
  92. el.textContent = 'Normal Res';
  93. } else if (resolution === 1) {
  94. resolution = 1.5;
  95. el.textContent = 'High Res';
  96. } else {
  97. resolution = 2;
  98. el.textContent = 'Retina Res';
  99. }
  100. unitSprites = {};
  101. resize();
  102. window.statusBar();
  103. }
  104. window.setFPS = function () {
  105. var el = document.getElementById('fps');
  106. if (rate === 0) {
  107. el.textContent = '45 FPS'
  108. rate = 22;
  109. } else if (rate === 22) {
  110. el.textContent = '40 FPS'
  111. rate = 25;
  112. } else if (rate === 25) {
  113. el.textContent = '35 FPS'
  114. rate = 28;
  115. } else if (rate === 28) {
  116. el.textContent = '30 FPS';
  117. rate = 33;
  118. } else if (rate === 33) {
  119. el.textContent = '25 FPS';
  120. rate = 40;
  121. } else if (rate === 40) {
  122. el.textContent = '20 FPS';
  123. rate = 50;
  124. } else {
  125. el.textContent = 'Unlim FPS';
  126. rate = 0;
  127. }
  128. window.statusBar();
  129. }
  130.  
  131. window.callUpdate = function () {
  132. requestAnimFrame(callUpdate);
  133. currentTime = window.performance.now();
  134. var a = currentTime - then;
  135. if (a >= rate) {
  136. then = currentTime;
  137. updateGameLoop(a);
  138. }
  139. updateMenuLoop(a)
  140. }
  141.  
  142. window.makeUI = function () {
  143. if (window.hasMadeUI) return;
  144. window.hasMadeUI = true;
  145. window.statusItems.sort(function (a, b) {
  146. return a.order - b.order;
  147. })
  148. var levels = [];
  149. window.UIList.forEach((item) => {
  150. if (!levels[item.level]) levels[item.level] = [];
  151. levels[item.level].push(item)
  152. })
  153.  
  154. levels = levels.filter((a) => {
  155. if (a) {
  156. a.sort(function (a, b) {
  157. return a.x - b.x;
  158. })
  159. return true;
  160. } else {
  161. return false;
  162. }
  163. })
  164.  
  165. var headAppend = document.getElementsByTagName("head")[0],
  166. style = document.createElement("div");
  167.  
  168. var toast = document.createElement('div');
  169. toast.id = "snackbar";
  170. var css = document.createElement('div');
  171.  
  172. css.innerHTML = '<style>\n\
  173. #snackbar {\n\
  174. visibility: hidden;\n\
  175. min-width: 250px;\n\
  176. margin-left: -125px;\n\
  177. background-color: rgba(40, 40, 40, 0.5);\n\
  178. color: #fff;\n\
  179. text-align: center;\n\
  180. border-radius: 4px;\n\
  181. padding: 10px;\n\
  182. font-family: "regularF";\n\
  183. font-size: 20px;\n\
  184. position: fixed;\n\
  185. z-index: 100;\n\
  186. left: 50%;\n\
  187. top: 30px;\n\
  188. }\n\
  189. #snackbar.show {\n\
  190. visibility: visible;\n\
  191. -webkit-animation: fadein 0.5s;\n\
  192. animation: fadein 0.5s;\n\
  193. }\n\
  194. #snackbar.hide {\n\
  195. visibility: visible;\n\
  196. -webkit-animation: fadeout 0.5s;\n\
  197. animation: fadeout 0.5s;\n\
  198. }\n\
  199. @-webkit-keyframes fadein {\n\
  200. from {top: 0; opacity: 0;}\n\
  201. to {top: 30px; opacity: 1;}\n\
  202. }\n\
  203. @keyframes fadein {\n\
  204. from {top: 0; opacity: 0;}\n\
  205. to {top: 30px; opacity: 1;}\n\
  206. }\n\
  207. @-webkit-keyframes fadeout {\n\
  208. from {top: 30px; opacity: 1;}\n\
  209. to {top: 0; opacity: 0;}\n\
  210. }\n\
  211. @keyframes fadeout {\n\
  212. from {top: 30px; opacity: 1;}\n\
  213. to {top: 0; opacity: 0;}\n\
  214. }\n\
  215. </style>'
  216. var height = levels.length * (14 + 19) + (levels.length - 1) * 7 + 15;
  217. style.innerHTML = "<style>\n\
  218. #noobscriptUI, #noobscriptUI > div > div {\n\
  219. background-color:rgba(40,40,40,.5);\n\
  220. margin-left: 3px;\n\
  221. border-radius:4px;\n\
  222. pointer-events:all\n\
  223. }\n\
  224. #noobscriptUI {\n\
  225. top: -" + (height + 12) + "px;\n\
  226. transition: 1s;\n\
  227. margin-left:10px;\n\
  228. position:absolute;\n\
  229. padding-left:24px;\n\
  230. margin-top:9px;\n\
  231. padding-top:15px;\n\
  232. width:580px;\n\
  233. height: " + height + "px;\n\
  234. font-family:arial;\n\
  235. left:25%\n\
  236. }\n\
  237. #noobscriptUI:hover{\n\
  238. top:0px\n\
  239. }\n\
  240. #noobscriptUI > div > div {\n\
  241. color:#fff;\n\
  242. padding:7px;\n\
  243. height:19px;\n\
  244. display:inline-block;\n\
  245. cursor:pointer;\n\
  246. font-size:15px\n\
  247. }\n\
  248. </style>"
  249.  
  250. headAppend.appendChild(style);
  251. headAppend.appendChild(css);
  252.  
  253.  
  254. var contAppend = document.getElementById("gameUiContainer"),
  255. menuA = document.createElement("div");
  256.  
  257. var code = ['<div id="noobscriptUI">\n'];
  258.  
  259. levels.forEach((items, i) => {
  260. code.push(i === 0 ? ' <div>\n' : ' <div style="margin-top:7px;">\n');
  261. items.forEach((el) => {
  262. code.push(' ' + el.html + '\n');
  263. })
  264. code.push(' </div>\n');
  265. })
  266. code.push(' <div id="confinfo" style="margin-top:4px; color: white; text-align: center; font-size: 10px; white-space:pre"></div>')
  267. code.push('</div>');
  268.  
  269. menuA.innerHTML = code.join("");
  270. contAppend.insertBefore(menuA, contAppend.firstChild)
  271. contAppend.appendChild(toast)
  272. var toastTimeout = false;
  273. window.showToast = function (msg) {
  274. toast.textContent = msg;
  275.  
  276. if (toastTimeout) clearTimeout(toastTimeout);
  277. else toast.className = "show";
  278. toastTimeout = setTimeout(function () {
  279. toast.className = 'hide'
  280. setTimeout(function () {
  281. toast.className = '';
  282. }, 400);
  283. toastTimeout = false;
  284. }, 3000);
  285. }
  286. window.statusBar = function () {
  287. var el = document.getElementById('confinfo');
  288. var text = [];
  289.  
  290. window.statusItems.forEach((item, i) => {
  291. if (i !== 0) text.push(' ');
  292. if (item.name) text.push(item.name + ': ');
  293. text.push(item.value());
  294. })
  295.  
  296. el.textContent = text.join('');
  297. }
  298. window.statusBar();
  299.  
  300. window.initFuncs.forEach((func) => {
  301. func();
  302. })
  303. }
  304. setTimeout(() => {
  305. window.makeUI();
  306. }, 1000)