Greasy Fork 还支持 简体中文。

Afk Script UPDATED

Press F to set the afk location and J to afk

  1. // ==UserScript==
  2. // @name Afk Script UPDATED
  3. // @namespace http://tampermonkey.net/
  4. // @version 3
  5. // @description Press F to set the afk location and J to afk
  6. // @author Mi300
  7. // @match https://diep.io/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @license dont copy my script thx
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. setTimeout (function() {
  14. function hook(target, callback){
  15. const check = () => {
  16. window.requestAnimationFrame(check)
  17. const func = CanvasRenderingContext2D.prototype[target]
  18.  
  19. if(func.toString().includes(target)){
  20.  
  21. CanvasRenderingContext2D.prototype[target] = new Proxy (func, {
  22. apply (method, thisArg, args) {
  23. callback(thisArg, args)
  24.  
  25. return Reflect.apply (method, thisArg, args)
  26. }
  27. });
  28. }
  29. }
  30. check()
  31. }
  32. const canvas = document.getElementById('canvas');
  33. const ctx = canvas.getContext('2d');
  34. let distance = [0, 0];
  35. let isActive = false;
  36. let storedPos = [0, 0];
  37. let arrowPos = [0, 0];
  38. let minimapPos = [0, 0];
  39. let minimapDim = [0, 0];
  40. let worldPosition = [0, 0];
  41.  
  42. let teamSnapshot = false;
  43. let team = '#f14e54';
  44. function hookMinimapArrow() {
  45. let drawInstructions = 0;
  46. let vertices = new Array(0);
  47.  
  48. hook('beginPath', function(context, args) {
  49. drawInstructions = 1;
  50. vertices = new Array(0);
  51. });
  52. hook('moveTo', function(context, args) {
  53. drawInstructions = 2;
  54. vertices.push(args);
  55. });
  56. hook('lineTo', function(context, args) {
  57. if (drawInstructions >= 2 && drawInstructions <= 5) {
  58. drawInstructions++;
  59. vertices.push(args);
  60. return;
  61. }
  62. drawInstructions = 0;
  63. });
  64. hook('fill', function(context, args) {
  65. if (context.globalAlpha != 1 || context.fillStyle != '#000000') {
  66. return;
  67. }
  68. if (drawInstructions === 4) {
  69. const pos = getAverage (vertices);
  70. arrowPos = pos;
  71. }
  72. });
  73. }
  74. function hookMinimap() {
  75. hook('strokeRect', function(context, args) {
  76. const t = context.getTransform();
  77. minimapPos = [t.e, t.f];
  78. minimapDim = [t.a, t.d];
  79. });
  80. hook('rect', function(context, args) {// purple: #bf7ff5, red: #f14e54, blue: #00b2e1, green: #00e16e
  81. const c = context.fillStyle;
  82. if (teamSnapshot) {
  83. if (c == '#f14e54') {
  84. team = c;
  85. }
  86. if (c == '#00b2e1') {
  87. team = c;
  88. }
  89. if (c == '#bf7ff5') {
  90. team = c;
  91. }
  92. if (c == '#00e16e') {
  93. team = c;
  94. }
  95. }
  96. });
  97. }
  98. hookMinimap();
  99. hookMinimapArrow();
  100. function getAverage(points) {
  101. let ret = [0, 0];
  102. points.forEach (point => {
  103. ret[0] += point[0];
  104. ret[1] += point[1];
  105. });
  106. ret[0] /= points.length;
  107. ret[1] /= points.length;
  108. return ret;
  109. }
  110. function getWorldPos () {
  111. const ret = [
  112. parseFloat((((arrowPos[0] - minimapPos[0] - minimapDim[0] / 2) / minimapDim[0] * 100) * 460).toFixed (3)),
  113. parseFloat((((arrowPos[1] - minimapPos[1] - minimapDim[1] / 2) / minimapDim[1] * 100) * 460).toFixed (3)),
  114. ]
  115. return ret;
  116. }
  117. let lineWidth = 0;
  118. let cameraZoom = 0;
  119. CanvasRenderingContext2D.prototype.stroke = new Proxy(CanvasRenderingContext2D.prototype.stroke, {
  120. apply(method, self, args) {
  121. lineWidth = self.lineWidth;
  122. return Reflect.apply(method, self, args);
  123. }
  124. });
  125. CanvasRenderingContext2D.prototype.createPattern = new Proxy(CanvasRenderingContext2D.prototype.createPattern, {
  126. apply(method, self, args) {
  127. cameraZoom = 1 / lineWidth;
  128. return Reflect.apply(method, self, args);
  129. }
  130. });
  131. input.try_spawn = new Proxy(input.try_spawn, {
  132. apply(method, self, args) {
  133. teamSnapshot = true;
  134. setTimeout(function() {
  135. teamSnapshot = false;
  136. console.log (team)
  137. },1000);
  138. return Reflect.apply(method, self, args);
  139. }
  140. });
  141. function tick() {
  142. window.requestAnimationFrame(tick);
  143. worldPosition = getWorldPos();
  144. distance = getDist(
  145. worldPosition,
  146. storedPos,
  147. )
  148. if (isActive) {
  149. move();
  150. }
  151. drawAfkPos();
  152. }
  153. tick();
  154. function toGrid(dist) {
  155. return [
  156. dist[0] / ((1 - cameraZoom) * 8),
  157. dist[1] / ((1 - cameraZoom) * 8),
  158. dist[2] / ((1 - cameraZoom) * 8),
  159. ]
  160. }
  161. function drawAfkPos() {
  162. //distance
  163. const width = canvas.width;
  164. const height = canvas.height;
  165.  
  166. const grid = toGrid(distance);
  167. const size = 50;
  168. let toDraw = [
  169. width / 2 - grid[1],
  170. height / 2 - grid[2],
  171. ]
  172. ctx.beginPath();
  173. ctx.globalAlpha = 0.5;
  174. ctx.fillStyle = team
  175. ctx.arc(...toDraw, size, 0, Math.PI * 2, false);
  176. ctx.fill();
  177. ctx.stroke();
  178. ctx.globalAlpha = 1;
  179.  
  180. ctx.beginPath();
  181. ctx.lineWidth = 4;
  182. ctx.font = "23px bold arial"
  183. ctx.fillStyle = 'white';
  184. ctx.strokeStyle = 'black';
  185. if (isActive) {
  186. ctx.strokeText('[J] Locked', toDraw[0] - 50, toDraw[1] + 25);
  187. ctx.fillText('[J] Locked', toDraw[0] - 50, toDraw[1] + 25);
  188. } else {
  189. ctx.strokeText('[J] Unlocked', toDraw[0] - 50, toDraw[1] + 25);
  190. ctx.fillText('[J] Unlocked', toDraw[0] - 50, toDraw[1] + 25);
  191. }
  192.  
  193. }
  194. document.addEventListener('keydown', e => {
  195. if(e.key === 'j') {
  196. isActive = !isActive;
  197. input.key_up (83);
  198. input.key_up (87);
  199. input.key_up (68);
  200. input.key_up (65);
  201. }
  202. if(e.key === 'f') {
  203. storedPos = worldPosition;
  204. }
  205. });
  206. function getDist(t1, t2) {
  207. const distX = t1[0] - t2[0];
  208. const distY = t1[1] - t2[1];
  209. return [Math.hypot(distX, distY), distX, distY];
  210. };
  211. function move() {
  212. if (distance[1] < 0.1) {
  213. input.key_up (65);
  214. input.key_down (68);
  215. } else if (distance[1] > -0.1) {
  216. input.key_up (68);
  217. input.key_down (65);
  218. } else {
  219. input.key_up (68);
  220. input.key_up (65);
  221. }
  222.  
  223. if (distance[2] < 0.1) {
  224. input.key_up (87);
  225. input.key_down (83);
  226. } else if (distance[2] > 0.1) {
  227. input.key_up (83);
  228. input.key_down (87);
  229. } else {
  230. input.key_up (83);
  231. input.key_up (87);
  232. }
  233. }
  234. },2500);