Greasy Fork 还支持 简体中文。

DigDig.io AutoOreX

AutoOreX Collects Diamond, Gold, Urananium & Amethyst!

  1. // ==UserScript==
  2. // @name DigDig.io AutoOreX
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description AutoOreX Collects Diamond, Gold, Urananium & Amethyst!
  6. // @author Stronurus
  7. // @match *://digdig.io/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=microsoft.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. let timeRan = 0;
  17.  
  18. let lastTime = 0;
  19.  
  20. const chunkSize = 64;
  21. const resourcePositions = [];
  22.  
  23. let isDead = false;
  24. let isRunning = false;
  25.  
  26. let health = 0;
  27.  
  28. let border = null;
  29.  
  30. const chunks = [];
  31.  
  32. let serverIndex = 0;
  33. const servers = [];
  34.  
  35. const modes = [ 'ffa'];
  36.  
  37. let angle = Math.random() * Math.PI * 2;
  38.  
  39. function changeAngle() {
  40. angle = Math.random() * 2 * Math.PI - Math.PI;
  41.  
  42. const interval = Math.random() * 19000 + 1000; // random interval between 1 and 20 seconds
  43.  
  44. setTimeout(changeAngle, interval);
  45. }
  46.  
  47. changeAngle();
  48.  
  49. init();
  50.  
  51. async function init() {
  52.  
  53. for ( let i = 0; i < modes.length; i ++ ) {
  54.  
  55. const response = await fetch( 'https://api.n.m28.io/endpoint/digdig-' + modes[ i ] + '/findEach' );
  56.  
  57. const json = await response.json();
  58.  
  59. for ( let key in json.servers ) {
  60.  
  61. servers.push( json.servers[ key ].id );
  62.  
  63. }
  64.  
  65. }
  66.  
  67. isRunning = true;
  68.  
  69. window.addEventListener( 'keyup', function ( event ) {
  70.  
  71. if ( String.fromCharCode( event.keyCode ) === 'B' ) {
  72.  
  73. isRunning = ! isRunning;
  74.  
  75. setTimeout( function () {
  76.  
  77. setAttack( isRunning );
  78.  
  79. }, 0 );
  80.  
  81. }
  82.  
  83. } );
  84.  
  85. }
  86.  
  87. window.requestAnimationFrame = new Proxy( window.requestAnimationFrame, {
  88. apply( target, thisArgs, args ) {
  89.  
  90. if ( isRunning === true ) {
  91.  
  92. args[ 0 ] = new Proxy( args[ 0 ], {
  93. apply( target, thisArgs, args ) {
  94.  
  95. isDead = false;
  96.  
  97. healthX.length = 0;
  98. health = 0;
  99.  
  100. border = null;
  101.  
  102. resourcePositions.length = 0;
  103.  
  104. Reflect.apply( ...arguments );
  105.  
  106. const now = Date.now();
  107.  
  108. if ( isRunning && lastTime > 0 ) {
  109.  
  110. timeRan += now - lastTime;
  111.  
  112. }
  113.  
  114. lastTime = now;
  115.  
  116. if ( isDead === true || health <= 0 ) {
  117.  
  118. pressEnter();
  119.  
  120. return;
  121.  
  122. }
  123.  
  124. if ( resourcePositions.length > 0 ) {
  125.  
  126. let target = null;
  127.  
  128. if ( border !== null ) {
  129.  
  130. const [ bx, by, br ] = border;
  131.  
  132. for ( let i = 0; i < resourcePositions.length; i ++ ) {
  133.  
  134. const [ x, y ] = resourcePositions[ i ];
  135.  
  136. if ( Math.hypot( x - bx, y - by ) < br ) {
  137.  
  138. target = resourcePositions[ i ];
  139. break;
  140.  
  141. }
  142.  
  143. }
  144.  
  145. } else {
  146.  
  147. target = resourcePositions[ 0 ];
  148.  
  149. }
  150.  
  151. if (target !== null) {
  152.  
  153. mouseMove(target[0], target[1]);
  154.  
  155. for ( let i = 0; i < resourcePositions.length; i ++ ) {
  156.  
  157. const [ x, y ] = resourcePositions[ i ];
  158.  
  159. if (x === target[0] && y === target[1]) {
  160.  
  161. resourcePositions.splice(i, 1);
  162. break;
  163.  
  164. }
  165.  
  166. }
  167.  
  168. return;
  169.  
  170. }
  171.  
  172. }
  173.  
  174. mouseMove(
  175. ( Math.cos( angle ) * 0.5 + 0.5 ) * window.innerWidth,
  176. ( Math.sin( angle ) * 0.5 + 0.5 ) * window.innerHeight
  177. );
  178.  
  179. if ( health <= 0.00 ) {
  180.  
  181. angle = Math.random() * Math.PI * 2;
  182.  
  183. serverIndex = ( serverIndex + 1 ) % servers.length;
  184.  
  185. cp6.forceServerID( servers[ serverIndex ] );
  186.  
  187. while ( chunks.length > 0 ) {
  188.  
  189. chunks.shift().resources.length = 0;
  190.  
  191. }
  192.  
  193. }
  194.  
  195. }
  196. });
  197.  
  198. }
  199.  
  200. return Reflect.apply( ...arguments );
  201.  
  202. }
  203. } );
  204.  
  205. const Context = CanvasRenderingContext2D.prototype;
  206.  
  207. Context.arc = new Proxy( Context.arc, {
  208. apply( target, ctx, [ x, y, r ] ) {
  209.  
  210. Reflect.apply( ...arguments );
  211.  
  212. if ( isRunning && ctx.fillStyle === '#222222' && x !== 0 && y !== 0 ) {
  213.  
  214. border = [ x, y, r ];
  215.  
  216. ctx.save();
  217.  
  218. ctx.translate( window.innerWidth / 2, 10 );
  219.  
  220. ctx.font = 'bolder 30px Ubuntu';
  221.  
  222. ctx.textAlign = 'center';
  223. ctx.textBaseline = 'top';
  224.  
  225. const a = ' AutoOreX V:0.3 Mining...';
  226.  
  227. ctx.lineWidth = 2;
  228. ctx.strokeStyle = '#000';
  229.  
  230. ctx.strokeText( a, 0, 0 );
  231.  
  232. ctx.fillStyle = '#FFD700';
  233. ctx.fillText( a, 0, 0 );
  234.  
  235. const seconds = timeRan / 1000;
  236. const mins = Math.floor( seconds / 60 );
  237.  
  238. const b ='Running for ' + ( mins > 0 ? mins + 'm ' : '' ) + ( seconds % 60 ).toFixed( 1 ) + 's';
  239.  
  240. ctx.font = 'bolder 18px Ubuntu';
  241.  
  242. ctx.strokeText( b, 0, 32 );
  243. ctx.fillText( b, 0, 32 );
  244.  
  245. ctx.restore();
  246.  
  247. }
  248.  
  249. }
  250. } );
  251.  
  252. Context.drawImage = new Proxy( Context.drawImage, {
  253. apply( target, thisArgs, [ { resources } ] ) {
  254.  
  255. if ( resources !== undefined ) {
  256.  
  257. const { a, d, e, f } = thisArgs.getTransform();
  258.  
  259. for ( let i = 0; i < resources.length; i ++ ) {
  260.  
  261. const [ m, n, ] = resources[ i ];
  262.  
  263. resourcePositions.push( [
  264. m / chunkSize * a + e,
  265. n / chunkSize * d + f
  266. ] );
  267. }
  268.  
  269. setTimeout(() => {
  270. resourcePositions.length = 0;
  271. }, 5000);
  272. }
  273.  
  274. return Reflect.apply( ...arguments );
  275.  
  276. }
  277. } );
  278.  
  279. const healthX = [];
  280.  
  281. const params = {
  282. apply( target, thisArgs, [ x ] ) {
  283.  
  284. healthX[ target.name === 'moveTo' ? 0 : 1 ] = x;
  285.  
  286. return Reflect.apply( ...arguments );
  287.  
  288. }
  289. };
  290.  
  291. Context.moveTo = new Proxy( Context.moveTo, params );
  292. Context.lineTo = new Proxy( Context.lineTo, params );
  293.  
  294. Context.stroke = new Proxy( Context.stroke, {
  295. apply( target, thisArgs, args ) {
  296.  
  297. if ( thisArgs.strokeStyle === '#75dd34' ) {
  298.  
  299. health = ( healthX[ 0 ] - healthX[ 1 ] ) / ( 2 * healthX[ 0 ] );
  300.  
  301. }
  302.  
  303. return Reflect.apply( ...arguments );
  304.  
  305. }
  306. } );
  307.  
  308. const OffscreenContext = typeof OffscreenCanvasRenderingContext2D !== 'undefined' ?
  309. OffscreenCanvasRenderingContext2D.prototype : Context;
  310.  
  311. OffscreenContext.drawImage = new Proxy( OffscreenContext.drawImage, {
  312. apply( target, thisArgs, [ { resources } ] ) {
  313.  
  314. if ( resources !== undefined ) {
  315.  
  316. console.log( 'here!' );
  317.  
  318. thisArgs.canvas.resources = resources;
  319.  
  320. if (resources.length > 0) {
  321. setTimeout(() => {
  322. resourcePositions.length = 0;
  323. }, 5000); // wait 5 seconds before clearing resourcePositions
  324. }
  325.  
  326. }
  327.  
  328. return Reflect.apply( ...arguments );
  329.  
  330. }
  331. } );
  332.  
  333. OffscreenContext.fillRect = new Proxy( OffscreenContext.fillRect, {
  334. apply( target, thisArgs, args ) {
  335.  
  336. if ( thisArgs.fillStyle === '#000000' ) {
  337.  
  338. isDead = true;
  339.  
  340. }
  341.  
  342. return Reflect.apply( ...arguments );
  343.  
  344. }
  345. } );
  346.  
  347. OffscreenContext.putImageData = new Proxy( OffscreenContext.putImageData, {
  348. apply( target, thisArgs, [ { data } ] ) {
  349.  
  350. console.log( thisArgs.canvas );
  351.  
  352. if ( thisArgs.canvas.width === chunkSize && thisArgs.canvas.height === chunkSize ) {
  353.  
  354. thisArgs.canvas.resources = [];
  355.  
  356. for ( let i = 0; i < data.length; i += 4 ) {
  357.  
  358. if ( isResourceColor( data[ i ], data[ i + 1 ], data[ i + 2 ] ) ) {
  359.  
  360. const index = i / 4;
  361.  
  362. thisArgs.canvas.resources.push( [
  363. index % chunkSize,
  364. Math.floor( index / chunkSize )
  365. ] );
  366.  
  367. }
  368.  
  369. }
  370.  
  371. chunks.push( thisArgs.canvas );
  372.  
  373. }
  374.  
  375. return Reflect.apply( ...arguments );
  376.  
  377. }
  378. } );
  379.  
  380. OffscreenContext.fillRect = new Proxy( OffscreenContext.fillRect, {
  381. apply( target, thisArgs, [ x, y, width, height ] ) {
  382.  
  383. if ( thisArgs.canvas.width === chunkSize && thisArgs.canvas.height === chunkSize ) {
  384.  
  385. if ( thisArgs.canvas.resources === undefined ) {
  386.  
  387. thisArgs.canvas.resources = [];
  388.  
  389. }
  390.  
  391. if ( isResourceColor( thisArgs.fillStyle ) ) {
  392.  
  393. thisArgs.canvas.resources.push( [ x, y ] );
  394.  
  395. }
  396.  
  397. }
  398.  
  399. return Reflect.apply( ...arguments );
  400.  
  401. }
  402. } );
  403.  
  404. OffscreenContext.clearRect = new Proxy( OffscreenContext.clearRect, {
  405. apply( target, thisArgs, [ x, y, width, height ] ) {
  406.  
  407. if ( thisArgs.canvas.resources !== undefined ) {
  408.  
  409. if ( width === chunkSize && height === chunkSize ) {
  410.  
  411. thisArgs.canvas.resources.length = 0;
  412.  
  413. } else {
  414.  
  415. for ( let i = 0; i < thisArgs.canvas.resources.length; i ++ ) {
  416.  
  417. const [ m, n ] = thisArgs.canvas.resources[ i ];
  418.  
  419. if ( m === x && n === y ) {
  420.  
  421. thisArgs.canvas.resources.splice( i, 1 );
  422. break;
  423.  
  424. }
  425.  
  426. }
  427.  
  428. }
  429.  
  430. }
  431.  
  432. return Reflect.apply( ...arguments );
  433.  
  434. }
  435. } );
  436.  
  437. function isResourceColor
  438. ( r, g, b ) {
  439.  
  440. if ( arguments.length === 1 ) {
  441.  
  442. g = parseInt( r.substring( 3, 5 ), 16 );
  443. b = parseInt( r.substring( 5, 7 ), 16 );
  444. r = parseInt( r.substring( 1, 3 ), 16 );
  445.  
  446. }
  447.  
  448. return (
  449. Math.hypot( 0xa5 - r, 0x9e - g, 0x15 - b ) < 25 ||
  450. Math.hypot( 0x3c - r, 0xc4 - g, 0x3d - b ) < 25 ||
  451. Math.hypot( 0x6d - r, 0xd6 - g, 0xff - b ) < 25 ||
  452. Math.hypot( 0x31 - r, 0xa5 - g, 0x9b - b ) < 25 ||
  453. Math.hypot( 0x35 - r, 0xa8 - g, 0x31 - b ) < 25 ||
  454. Math.hypot( 0xaf - r, 0x31 - g, 0xb2 - b ) < 25
  455. );
  456. }
  457.  
  458. function pressEnter() {
  459.  
  460. keyEvent( 'keydown', 13 );
  461. keyEvent( 'keyup', 13 );
  462.  
  463. }
  464.  
  465. function setAttack( bool ) {
  466.  
  467. keyEvent( bool !== false ? 'keydown' : 'keyup', 32 );
  468.  
  469. }
  470.  
  471. function setHeal( bool ) {
  472.  
  473. keyEvent( bool !== false ? 'keydown' : 'keyup', 16 );
  474.  
  475. }
  476.  
  477. function keyEvent( type, keyCode ) {
  478.  
  479. window.dispatchEvent( new KeyboardEvent( type, { keyCode } ) );
  480.  
  481. }
  482.  
  483. function mouseMove( clientX, clientY ) {
  484.  
  485. const randomness = 25; // adjust the randomness to your liking
  486.  
  487. const newX = clientX + (Math.random() * randomness * 2) - randomness;
  488. const newY = clientY + (Math.random() * randomness * 2) - randomness;
  489.  
  490. window.Module.canvas.dispatchEvent(
  491. new MouseEvent( 'mousemove', {
  492. clientX: newX,
  493. clientY: newY
  494. } )
  495. );
  496. }
  497.  
  498. })();