Krunker.IO AimLock

Locks aim to the nearest player in krunker.io

目前为 2021-12-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Krunker.IO AimLock
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.41
  5. // @description Locks aim to the nearest player in krunker.io
  6. // @author Zertalious (Zert)
  7. // @match *://krunker.io/*
  8. // @icon https://www.google.com/s2/favicons?domain=krunker.io
  9. // @grant none
  10. // @run-at document-end
  11. // @require https://unpkg.com/three@latest/build/three.min.js
  12. // ==/UserScript==
  13.  
  14. const tempVector = new THREE.Vector3();
  15.  
  16. const tempObject = new THREE.Object3D();
  17.  
  18. tempObject.rotation.order = 'YXZ';
  19.  
  20. const geometry = new THREE.SphereGeometry( 10 );
  21.  
  22. const material = new THREE.MeshLambertMaterial( {
  23. color: 'red',
  24. wireframe: true
  25. } );
  26.  
  27. const meshes = [];
  28.  
  29. let isActive = true;
  30.  
  31. let scene;
  32.  
  33. WeakMap.prototype.set = new Proxy( WeakMap.prototype.set, {
  34. apply( target, thisArgs, args ) {
  35.  
  36. if ( args[ 0 ].type === 'Scene' && args[ 0 ].name === 'Main' ) {
  37.  
  38. scene = args[ 0 ];
  39.  
  40. }
  41.  
  42. return Reflect.apply( ...arguments );
  43.  
  44. }
  45. } );
  46.  
  47. function animate() {
  48.  
  49. window.requestAnimationFrame( animate );
  50.  
  51. if ( isActive === false || scene === undefined ) {
  52.  
  53. return;
  54.  
  55. }
  56.  
  57. const players = [];
  58.  
  59. let myPlayer;
  60.  
  61. for ( let i = 0; i < scene.children.length; i ++ ) {
  62.  
  63. const child = scene.children[ i ];
  64.  
  65. if ( child.type === 'Object3D' ) {
  66.  
  67. try {
  68.  
  69. if ( child.children[ 0 ].children[ 0 ].type === 'PerspectiveCamera' ) {
  70.  
  71. myPlayer = child;
  72.  
  73. } else {
  74.  
  75. players.push( child );
  76.  
  77. }
  78.  
  79. } catch ( err ) {}
  80.  
  81. }
  82.  
  83. }
  84.  
  85. if ( players.length < 2 ) {
  86.  
  87. return;
  88.  
  89. }
  90.  
  91. let targetPlayer;
  92. let minDistance = Infinity;
  93.  
  94. for ( let i = 0; i < players.length; i ++ ) {
  95.  
  96. const player = players[ i ];
  97.  
  98. if ( player.position.x === myPlayer.position.x && player.position.z === myPlayer.position.z ) {
  99.  
  100. continue;
  101.  
  102. }
  103.  
  104. if ( player.firstTime !== true ) {
  105.  
  106. const mesh = new THREE.Mesh( geometry, material );
  107.  
  108. meshes.push( mesh );
  109.  
  110. player.add( mesh );
  111.  
  112. player.firstTime = true;
  113.  
  114. }
  115.  
  116. const distance = player.position.distanceTo( myPlayer.position );
  117.  
  118. if ( distance < minDistance ) {
  119.  
  120. targetPlayer = player;
  121.  
  122. minDistance = distance;
  123.  
  124. }
  125.  
  126. }
  127.  
  128. if ( targetPlayer === undefined ) {
  129.  
  130. return;
  131.  
  132. }
  133.  
  134. tempVector.setScalar( 0 );
  135.  
  136. targetPlayer.children[ 0 ].children[ 0 ].localToWorld( tempVector );
  137.  
  138. tempObject.position.copy( myPlayer.position );
  139.  
  140. tempObject.lookAt( tempVector );
  141.  
  142. myPlayer.children[ 0 ].rotation.x = - tempObject.rotation.x;
  143. myPlayer.rotation.y = tempObject.rotation.y + Math.PI;
  144.  
  145. }
  146.  
  147. animate();
  148.  
  149. window.addEventListener( 'keydown', function ( event ) {
  150.  
  151. if ( String.fromCharCode( event.keyCode ) === 'G' ) {
  152.  
  153. isActive = ! isActive;
  154.  
  155. for ( let i = 0; i < meshes.length; i ++ ) {
  156.  
  157. meshes[ i ].visible = isActive;
  158.  
  159. }
  160.  
  161. }
  162.  
  163. } );
  164.  
  165. const shouldShowAd = window.localStorage.showAd !== false && new URLSearchParams( window.location.search ).get( 'showAd' ) !== 'false';
  166.  
  167. const el = document.createElement( 'div' );
  168.  
  169. el.innerHTML = `<style>
  170.  
  171. .dialog {
  172. position: absolute;
  173. left: 50%;
  174. top: 50%;
  175. padding: 20px;
  176. background: rgba(0, 0, 0, 0.8);
  177. border: 6px solid rgba(0, 0, 0, 0.2);
  178. color: #fff;
  179. transform: translate(-50%, -50%);
  180. text-align: center;
  181. z-index: 999999;
  182. }
  183.  
  184. .dialog * {
  185. color: #fff;
  186. }
  187.  
  188. .close {
  189. position: absolute;
  190. right: 5px;
  191. top: 5px;
  192. width: 20px;
  193. height: 20px;
  194. opacity: 0.5;
  195. cursor: pointer;
  196. }
  197.  
  198. .close:before, .close:after {
  199. content: ' ';
  200. position: absolute;
  201. left: 50%;
  202. top: 50%;
  203. width: 100%;
  204. height: 20%;
  205. transform: translate(-50%, -50%) rotate(-45deg);
  206. background: #fff;
  207. }
  208.  
  209. .close:after {
  210. transform: translate(-50%, -50%) rotate(45deg);
  211. }
  212.  
  213. .close:hover {
  214. opacity: 1;
  215. }
  216.  
  217. .btn {
  218. cursor: pointer;
  219. padding: 0.5em;
  220. background: red;
  221. border: 3px solid rgba(0, 0, 0, 0.2);
  222. margin-bottom: 5px;
  223. }
  224.  
  225. .btn:active {
  226. transform: scale(0.8);
  227. }
  228.  
  229. </style>
  230. <div class="dialog">${shouldShowAd ? `<big>Loading ad...</big>` : `<div class="close" onclick="this.parentNode.style.display='none';"></div>
  231. <big>== Aimlocker ==</big>
  232. <br>
  233. <br>
  234. [G] to toggle aimlock
  235. <br>
  236. <br>
  237. By Zertalious
  238. <br>
  239. <br>
  240. <div class="btn" onclick="window.open('https://discord.gg/K24Zxy88VM')">Discord</div>
  241. <div class="btn" onclick="window.open('https://greasyfork.org/en/users/662330-zertalious', '_blank')">More scripts</div>` }
  242. </div>`;
  243.  
  244. while ( el.children.length > 0 ) {
  245.  
  246. document.body.appendChild( el.children[ 0 ] );
  247.  
  248. }
  249.  
  250. if ( shouldShowAd ) {
  251.  
  252. const url = new URL( window.location.href );
  253.  
  254. url.searchParams.set( 'showAd', 'false' );
  255.  
  256. window.location.href = 'https://adf.ly/10891457/' + url.href;
  257.  
  258. }