DigDig.IO Minimap

Minimap for digdig.io

目前為 2021-09-10 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name DigDig.IO Minimap
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.4
  5. // @description Minimap for digdig.io
  6. // @author Zertalious (Zert)
  7. // @match *://digdig.io/*
  8. // @icon https://www.google.com/s2/favicons?domain=digdig.io
  9. // @require https://cdn.jsdelivr.net/gh/Qwokka/WAIL@9ed21abc43045e19f9b3756de109a6e361fb9292/wail.js
  10. // ==/UserScript==
  11.  
  12. const _instantiateStreaming = WebAssembly.instantiateStreaming;
  13.  
  14. WebAssembly.instantiateStreaming = function () {
  15.  
  16. return _instantiateStreaming( new Response() );
  17.  
  18. }
  19.  
  20. const _instantiate = WebAssembly.instantiate;
  21.  
  22. WebAssembly.instantiate = function ( buffer, imports ) {
  23.  
  24. const array = new Uint8Array( buffer );
  25.  
  26. find( array, [
  27. OP_SELECT,
  28. OP_F64_PROMOTE_F32,
  29. OP_TEE_LOCAL, - 1,
  30. OP_GET_LOCAL, - 1,
  31. OP_F64_MUL,
  32. OP_F64_ADD,
  33. OP_F64_GE,
  34. OP_BR_IF, 0
  35. ], function ( start, end ) {
  36.  
  37. array[ end - 1 ] = OP_DROP;
  38. array[ end ] = OP_NOP;
  39.  
  40. } );
  41.  
  42. return _instantiate( buffer, imports );
  43.  
  44. }
  45.  
  46. function find( array, search, callback ) {
  47.  
  48. main: for ( let i = 0; i < array.length; i ++ ) {
  49.  
  50. for ( let j = 0; j < search.length; j ++ ) {
  51.  
  52. if ( search[ j ] !== - 1 && array[ i + j ] !== search[ j ] ) {
  53.  
  54. continue main;
  55.  
  56. }
  57.  
  58. }
  59.  
  60. callback( i, i + search.length - 1 );
  61.  
  62. }
  63.  
  64. }
  65.  
  66. function Float32ToArray( x ) {
  67.  
  68. return new Uint8Array( new Float32Array( [ x ] ).buffer );
  69.  
  70. }
  71.  
  72. function Float64ToArray( x ) {
  73.  
  74. return new Uint8Array( new Float64Array( [ x ] ).buffer );
  75.  
  76. }
  77.  
  78. const CTX = CanvasRenderingContext2D.prototype;
  79. let temp;
  80. CTX.arc = new Proxy( CTX.arc, {
  81. apply( target, ctx, args ) {
  82. if ( [ 25, 28, 3, 50, 9 ].indexOf( args[ 2 ] ) === - 1 && ctx.fillStyle === '#222222' ) {
  83. temp = args;
  84. }
  85. return Reflect.apply( ...arguments );
  86. }
  87. } );
  88.  
  89. let offsetY = window.innerHeight;
  90. CTX.fill = new Proxy( CTX.fill, {
  91. apply( target, ctx, args ) {
  92. Reflect.apply( ...arguments );
  93. if ( temp ) {
  94.  
  95. const [ x, y, r ] = temp;
  96. temp = null;
  97.  
  98. offsetY = Math.min( offsetY, window.innerHeight );
  99. const size = 50;
  100. const pointSize = 2;
  101. ctx.save();
  102. ctx.globalAlpha = 0.8;
  103. ctx.translate( 10 + size, offsetY - 10 - size );
  104. ctx.beginPath();
  105. ctx.arc( 0, 0, size, 0, Math.PI * 2 );
  106. ctx.fillStyle = '#111';
  107. ctx.fill();
  108. ctx.beginPath();
  109. const a = size - pointSize;
  110. ctx.arc( ( window.innerWidth / 2 - x ) / r * a, ( window.innerHeight / 2 - y ) / r * a, 2, 0, Math.PI * 2 );
  111. ctx.fillStyle = '#fff';
  112. ctx.fill();
  113. ctx.restore();
  114. ctx.beginPath();
  115. }
  116. }
  117. } );
  118.  
  119. let statsText;
  120.  
  121. const OffscreenContext = typeof OffscreenCanvasRenderingContext2D !== 'undefined' ?
  122. OffscreenCanvasRenderingContext2D.prototype : Context;
  123.  
  124. OffscreenContext.fillText = new Proxy( OffscreenContext.fillText, {
  125. apply( target, thisArgs, [ text ] ) {
  126.  
  127. if ( text === 'Stats' ) {
  128.  
  129. statsText = thisArgs.canvas;
  130.  
  131. }
  132.  
  133. return Reflect.apply( ...arguments );
  134.  
  135. }
  136. } );
  137.  
  138. OffscreenContext.drawImage = new Proxy( OffscreenContext.drawImage, {
  139. apply( target, thisArgs, [ image ] ) {
  140.  
  141. if ( image === statsText ) {
  142.  
  143. offsetY = thisArgs.getTransform().f;
  144.  
  145. }
  146.  
  147. return Reflect.apply( ...arguments );
  148.  
  149. }
  150. } );