Agar.io Reborn 2019

Rewritten in 2019. Previous name is Agar.io auto respawn (evergreen)

  1. // ==UserScript==
  2. // @name Agar.io Reborn 2019
  3. // @namespace http://redd.it/3ut09g
  4. // @description Rewritten in 2019. Previous name is Agar.io auto respawn (evergreen)
  5. // @version 110
  6. // @author condoriano
  7. // @icon http://i.imgur.com/YkDG9CI.png
  8. // @include http://agar.io/*
  9. // @include https://agar.io/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. var canvas = null;
  17. var ejectorLoop = null;
  18. var keysHold = {};
  19. var topPlayers = [];
  20. var copiedName = '';
  21.  
  22. $(document).ready(function() {
  23. canvas = document.getElementById('canvas');
  24. hookKeys();
  25. canvasModding();
  26. });
  27.  
  28. function hookKeys() {
  29. $(document).on('keyup', function(e) {
  30. var key = e.which || e.keyCode;
  31. keysHold[key] = false;
  32. if(key == 69) { // key E
  33. clearInterval(ejectorLoop);
  34. ejectorLoop = null;
  35. }
  36. else if(key >= 37 && key <= 40 || key >= 73 && key <= 76) handleMovementKeys();
  37. });
  38.  
  39. $(document).on('keydown', function(e) {
  40. var key = e.which || e.keyCode;
  41. var spKeys = e.ctrlKey || e.altKey || e.shiftKey;
  42. console.log('DEBUG: keydown ' + key);
  43. if(!document.getElementById('overlays') && !spKeys) {
  44. if(!keysHold[key]) {
  45. if(key == 69) { // key E
  46. if(!ejectorLoop) {
  47. ejectorLoop = setInterval(function() {
  48. window.onkeydown({ keyCode: 87 });
  49. window.onkeyup({ keyCode: 87 });
  50. }, 10);
  51. }
  52. }
  53. else if(key == 82) { // key R
  54. setIntervalX(function() {
  55. window.onkeydown({ keyCode: 87 }); // key W
  56. window.onkeyup({ keyCode: 87 });
  57. }, 120, 7);
  58. }
  59. else if(key == 84) { // key T
  60. setIntervalX(function() {
  61. window.onkeydown({ keyCode: 32 }); // key SPACE
  62. window.onkeyup({ keyCode: 32 });
  63. }, 60, 4);
  64. }
  65. else if(key == 83) { // key S
  66. var mEv = new MouseEvent('mousemove', { 'clientX': window.innerWidth / 2, 'clientY': window.innerHeight / 2 });
  67. canvas.dispatchEvent(mEv);
  68. }
  69. }
  70. keysHold[key] = true;
  71. if(key >= 37 && key <= 40 || key >= 73 && key <= 76) handleMovementKeys();
  72. }
  73. if(key >= 48 && key <= 57 && !spKeys && document.activeElement.tagName.toUpperCase() != 'INPUT') { // keys 0-9
  74. var playerPos = key == 48 ? 9 : key - 49;
  75. if(topPlayers[playerPos] !== undefined) {
  76. var newName = topPlayers[playerPos];
  77. //$('#nick').val(newName).change();
  78. window.prompt("Press CTRL+C to copy", newName);
  79. }
  80. }
  81. });
  82. }
  83.  
  84. function canvasModding() {
  85. var proxiedFillText = CanvasRenderingContext2D.prototype.fillText;
  86. CanvasRenderingContext2D.prototype.fillText = function() {
  87. if(arguments[0] == 'Leaderboard') {
  88. arguments[0] = 'tiny.cc/iAgar';
  89. topPlayers = [];
  90. }
  91. else if(parseInt(arguments[0]) >= 1 && parseInt(arguments[0]) <= 10) { // 1. xxx to 10. xxx
  92. var rank = parseInt(arguments[0]);
  93. if(rank <= 9 && arguments[0][1] == '.' || rank == 10 && arguments[0][2] == '.') {
  94. var tempName = arguments[0].substr(rank == 10 ? 4 : 3);
  95. topPlayers[rank - 1] = tempName;
  96. }
  97. }
  98. return proxiedFillText.apply(this, arguments);
  99. };
  100. var proxiedStrokeText = CanvasRenderingContext2D.prototype.strokeText;
  101. CanvasRenderingContext2D.prototype.strokeText = function() {
  102. return proxiedStrokeText.apply(this, arguments);
  103. };
  104. }
  105.  
  106. function handleMovementKeys() {
  107. var left = keysHold[37] || keysHold[74], up = keysHold[38] || keysHold[73], right = keysHold[39] || keysHold[76], down = keysHold[40] || keysHold[75];
  108. var point = [ window.innerWidth / 2, window.innerHeight / 2 ];
  109. if(left) point[0] -= 1000;
  110. if(up) point[1] -= 1000;
  111. if(right) point[0] += 1000;
  112. if(down) point[1] += 1000;
  113. canvas.dispatchEvent(new MouseEvent('mousemove', { 'clientX': point[0], 'clientY': point[1] }));
  114. }
  115.  
  116. function setIntervalX(callback, delay, repetitions) {
  117. var x = 0;
  118. var intervalID = window.setInterval(function () {
  119. callback();
  120. if(++x === repetitions) window.clearInterval(intervalID);
  121. }, delay);
  122. }
  123.  
  124. window.onbeforeunload = function() { return 'Quit game?'; };
  125.  
  126. })();