Afk script

made with much love

  1. // ==UserScript==
  2. // @name Afk script
  3. // @description made with much love
  4. // @version 0.1.5
  5. // @author Cazka#1820
  6. // @match *://diep.io/*
  7. // @grant GM_addStyle
  8. // @namespace https://gf.qytechs.cn/users/541070
  9. // ==/UserScript==
  10. /*
  11. * C L A S S E S
  12. */
  13. class Gui {
  14. constructor(title) {
  15. this._colors = ['#E8B18A', '#E666EA', '#9566EA', '#6690EA', '#E7D063', '#EA6666', '#92EA66', '#66EAE6'];
  16. this._buttons = [];
  17.  
  18. this._title = title;
  19. this._gui;
  20. this._guiHead;
  21. this._guiBody;
  22.  
  23. this._init();
  24.  
  25. this._enableShortcuts();
  26. }
  27.  
  28. _init() {
  29. const nonce = `a${(Math.random() * 1e5) | 0}`;
  30. GM_addStyle(
  31. `.${nonce} button{display:block;font-family:Ubuntu;color:#fff;text-shadow:-.1em -.1em 0 #000,0 -.1em 0 #000,.1em -.1em 0 #000,.1em 0 0 #000,.1em .1em 0 #000,0 .1em 0 #000,-.1em .1em 0 #000,-.1em 0 0 #000;opacity:.8;border:0;padding:.3em .5em;width:100%;transition:all .15s}.${nonce}{top:0;left:0;position:absolute}.${nonce} button:active:not([disabled]){filter:brightness(.9)}.${nonce} button:hover:not([disabled]):not(:active){filter:brightness(1.1)}`
  32. );
  33.  
  34. this._gui = document.createElement('div');
  35. this._guiHead = document.createElement('div');
  36. this._guiBody = document.createElement('div');
  37.  
  38. this._gui.className = `${nonce}`;
  39. this._guiBody.style.display = 'block';
  40.  
  41. document.body.appendChild(this._gui);
  42. this._gui.appendChild(this._guiHead);
  43. this._gui.appendChild(this._guiBody);
  44.  
  45. this._addButton(this._guiHead, this._title, () => {
  46. if (this._guiBody.style.display === 'block') {
  47. this._guiBody.style.display = 'none';
  48. } else {
  49. this._guiBody.style.display = 'block';
  50. }
  51. });
  52. }
  53. addButton(text, onclick, keyCode) {
  54. return this._addButton(this._guiBody, text, onclick, keyCode);
  55. }
  56. removeButton(button) {
  57. button.remove();
  58. button.active = false;
  59. }
  60. reset() {
  61. const head = this._buttons[0];
  62. this._buttons.forEach((x, i) => {
  63. if (i === 0) return;
  64. this.removeButton(x);
  65. });
  66. this._buttons = [head];
  67. }
  68. _addButton(parent, text, onclick, keyCode) {
  69. const button = document.createElement('button');
  70. button.innerHTML = text;
  71. button.keyCode = keyCode;
  72. button.onclick = onclick;
  73. button.style['background-color'] = this._colors[this._buttons.length % this._colors.length];
  74. button.addEventListener('contextmenu', (e) => e.preventDefault());
  75.  
  76. parent.appendChild(button);
  77. this._buttons.push(button);
  78. return button;
  79. }
  80. _enableShortcuts() {
  81. document.addEventListener('keydown', (event) => {
  82. if (document.getElementById('textInputContainer').style.display === 'block') return;
  83. this._buttons.forEach((button) => {
  84. if (button.keyCode === event.code) button.onclick();
  85. });
  86. });
  87. }
  88. }
  89. class Minimap {
  90. constructor() {
  91. this._minimapWidth;
  92. this._minimapHeight;
  93. this._x00;
  94. this._y00;
  95. this._pointX;
  96. this._pointY;
  97. this._viewportWidth;
  98. this._viewportHeight;
  99.  
  100. this._minimapHook();
  101. this._arrowHook();
  102. }
  103. get x() {
  104. return (this._pointX - this._x00) / this._minimapWidth;
  105. }
  106. get y() {
  107. return (this._pointY - this._y00) / this._minimapHeight;
  108. }
  109. _minimapHook() {
  110. let setTransformArgs;
  111.  
  112. const onsetTransform = (args) => {
  113. if (args[0] === args[3]) setTransformArgs = args;
  114. };
  115. const onstrokeRect = () => {
  116. if (setTransformArgs) {
  117. this._minimapWidth = setTransformArgs[0];
  118. this._minimapHeight = setTransformArgs[3];
  119. this._x00 = setTransformArgs[4];
  120. this._y00 = setTransformArgs[5];
  121. setTransformArgs = undefined;
  122. }
  123. };
  124. this._ctxHook('setTransform', onsetTransform);
  125. this._ctxHook('strokeRect', onstrokeRect);
  126. }
  127. _arrowHook() {
  128. let index = 0;
  129. const stack = Array(4);
  130.  
  131. let pointA;
  132. let pointB;
  133. let pointC;
  134.  
  135. const calculatePos = () => {
  136. const side1 = ((pointA[0] - pointB[0]) ** 2 + (pointA[1] - pointB[1]) ** 2) ** 0.5;
  137. const side2 = ((pointA[0] - pointC[0]) ** 2 + (pointA[1] - pointC[1]) ** 2) ** 0.5;
  138. const side3 = ((pointB[0] - pointC[0]) ** 2 + (pointB[1] - pointC[1]) ** 2) ** 0.5;
  139. if (~~side1 == ~~side2 && ~~side2 == ~~side3) return;
  140.  
  141. this._pointX = (pointA[0] + pointB[0] + pointC[0]) / 3;
  142. this._pointY = (pointA[1] + pointB[1] + pointC[1]) / 3;
  143. };
  144. const onbeginPath = () => {
  145. index = 0;
  146. stack[index++] = 0;
  147. };
  148. const onmoveTo = (args) => {
  149. if (index == 1 && stack[index - 1] == 0) {
  150. stack[index++] = 1;
  151. pointA = args;
  152. return;
  153. }
  154. index = 0;
  155. };
  156. const onlineTo = (args) => {
  157. if (index == 2 && stack[index - 1] == 1) {
  158. stack[index++] = 2;
  159. pointB = args;
  160. return;
  161. }
  162. if (index == 3 && stack[index - 1] == 2) {
  163. stack[index++] = 2;
  164. pointC = args;
  165. return;
  166. }
  167. index = 0;
  168. };
  169. const onfill = () => {
  170. if (index == 4 && stack[index - 1] == 2) {
  171. calculatePos();
  172. return;
  173. }
  174. index = 0;
  175. };
  176.  
  177. this._ctxHook('beginPath', onbeginPath);
  178. this._ctxHook('moveTo', onmoveTo);
  179. this._ctxHook('lineTo', onlineTo);
  180. this._ctxHook('fill', onfill);
  181. }
  182. _ctxHook(method, callback) {
  183. const target = window.CanvasRenderingContext2D.prototype;
  184. target[method] = new Proxy(target[method], {
  185. apply(target, thisArg, args) {
  186. callback(args);
  187. return target.apply(thisArg, args);
  188. },
  189. });
  190. }
  191. }
  192. class Player {
  193. constructor() {
  194. this._minimap = new Minimap();
  195. this._mouse = { x: NaN, y: NaN };
  196. }
  197. get x() {
  198. return this._minimap.x;
  199. }
  200. get y() {
  201. return this._minimap.y;
  202. }
  203. goto(x, y) {
  204. const dX = x - this.x;
  205. const dY = y - this.y;
  206. const len = Math.sqrt(dX ** 2 + dY ** 2);
  207. if (dX > 0) {
  208. unsafeWindow.input.keyDown('68');
  209. unsafeWindow.input.keyUp('65');
  210. } else {
  211. unsafeWindow.input.keyDown('65');
  212. unsafeWindow.input.keyUp('68');
  213. }
  214. if (dY > 0) {
  215. unsafeWindow.input.keyDown('83');
  216. unsafeWindow.input.keyUp('87');
  217. } else {
  218. unsafeWindow.input.keyDown('87');
  219. unsafeWindow.input.keyUp('83');
  220. }
  221. }
  222. }
  223. /*
  224. * H E L P E R F U N C T I O N S
  225. */
  226. function onbtnAfk() {
  227. this.active = !this.active;
  228. if (this.active) {
  229. this.x = player.x;
  230. this.y = player.y;
  231. this.innerHTML = 'AFK: ON';
  232. } else {
  233. unsafeWindow.input.keyUp('65');
  234. unsafeWindow.input.keyUp('68');
  235. unsafeWindow.input.keyUp('87');
  236. unsafeWindow.input.keyUp('83');
  237. this.innerHTML = 'AFK: OFF';
  238. }
  239. }
  240. function onbtnFreezeMouse() {
  241. this.active = !this.active;
  242. if (this.active) {
  243. this.innerHTML = 'Freeze Mouse: ON';
  244. } else {
  245. this.innerHTML = 'Freeze Mouse: OFF';
  246. }
  247. }
  248. function onbtnRepelNecro() {
  249. this.active = !this.active;
  250. if (this.active) {
  251. let repelTime = 25 * 1000;
  252. unsafeWindow.input.keyDown('16');
  253. this.repelInterval = setInterval(() => {
  254. unsafeWindow.input.keyDown('16');
  255. setTimeout(() => unsafeWindow.input.keyUp('16'), repelTime);
  256. }, 2 * repelTime + 1300);
  257. this.innerHTML = 'Repel Necro: ON';
  258. } else {
  259. clearInterval(this.repelInterval);
  260. unsafeWindow.input.keyUp('16');
  261. this.innerHTML = 'Repel Necro: OFF';
  262. }
  263. }
  264. function onbtnRepelOverlord() {
  265. this.active = !this.active;
  266. if (this.active) {
  267. let repelTime = 60 * 1000;
  268. unsafeWindow.input.keyDown('16');
  269. this.repelInterval = setInterval(() => {
  270. unsafeWindow.input.keyUp('16');
  271. setTimeout(() => unsafeWindow.input.keyDown('16'), 3000);
  272. }, repelTime);
  273. this.innerHTML = 'Repel Overlord: ON';
  274. } else {
  275. clearInterval(this.repelInterval);
  276. unsafeWindow.input.keyUp('16');
  277. this.innerHTML = 'Repel Overlord: OFF';
  278. }
  279. }
  280. function onbtnUpAndDown() {
  281. this.active = !this.active;
  282. if (this.active) {
  283. this.down = true;
  284. this.x = player.x;
  285. this.innerHTML = 'Up and Down: ON';
  286. } else {
  287. unsafeWindow.input.keyUp('65');
  288. unsafeWindow.input.keyUp('68');
  289. unsafeWindow.input.keyUp('87');
  290. unsafeWindow.input.keyUp('83');
  291. this.innerHTML = 'Up and Down: OFF';
  292. }
  293. }
  294. function onbtnDiscord() {
  295. window.open('https://discord.gg/5q2E3Sx');
  296. }
  297. /*
  298. * M A I N
  299. */
  300. const gui = new Gui('AFK by Cazka');
  301. const player = new Player();
  302.  
  303. let btnAfk = gui.addButton('AFK: OFF', onbtnAfk, 'KeyQ');
  304. let btnFreezeMouse = gui.addButton('Freeze Mouse: OFF', onbtnFreezeMouse, 'KeyG');
  305. let btnRepelNecro = gui.addButton('Repel Necro: OFF', onbtnRepelNecro, 'KeyR');
  306. let btnRepelOverlord = gui.addButton('Repel Overlord: OFF', onbtnRepelOverlord, 'KeyT');
  307. let btnUpAndDown = gui.addButton('Up and Down: OFF', onbtnUpAndDown);
  308. let btnDiscord = gui.addButton('Discord', onbtnDiscord);
  309.  
  310. unsafeWindow.requestAnimationFrame = new Proxy(unsafeWindow.requestAnimationFrame, {
  311. apply: function (target, thisArg, args) {
  312. if (btnAfk.active) player.goto(btnAfk.x, btnAfk.y);
  313. else if (btnUpAndDown.active) {
  314. if (btnUpAndDown.down) {
  315. player.goto(btnUpAndDown.x, 1);
  316. if (player.y >= 0.95) btnUpAndDown.down = false;
  317. } else {
  318. player.goto(btnUpAndDown.x, 0);
  319. if (player.y <= 1 - 0.95) btnUpAndDown.down = true;
  320. }
  321. }
  322. return target.apply(thisArg, args);
  323. },
  324. });
  325.  
  326. (function freezeMouse() {
  327. const canvas = document.getElementById('canvas');
  328. canvas.onmousemove = new Proxy(canvas.onmousemove, {
  329. apply(target, thisArg, args) {
  330. if (btnFreezeMouse?.active) return;
  331. target.apply(thisArg, args);
  332. },
  333. });
  334. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址