Agar.io Plus

Improves the functionality and style of agar.io

目前为 2017-06-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Agar.io Plus
  3. // @description Improves the functionality and style of agar.io
  4. // @match http://agar.io/*
  5. // @grant none
  6. // @version 0.4
  7. // @author Jack Burch + Tom Burris
  8. // @namespace https://greasyfork.org/en/users/46159
  9. // @icon http://bit.ly/2oT4wRk
  10. // @compatible chrome
  11. // @compatible firefox
  12. // @compatible safari
  13. // @compatible opera
  14. // @noframes
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. var css = "";
  21.  
  22. /* Compact Left Panel */
  23. css += ".quest-timer {width: auto; margin-left: 20px;}";
  24. var profilePanel = document.getElementsByClassName("agario-profile-panel")[0];
  25. profilePanel.appendChild(document.getElementById("dailyQuests"));
  26. document.getElementById("dailyQuests").appendChild(document.getElementsByClassName("quest-timer")[0]);
  27. var shopStuff = document.getElementsByClassName("agario-shop-panel")[0].childNodes;
  28. while(shopStuff.length) {
  29. profilePanel.appendChild(shopStuff[0]);
  30. }
  31. css += ".btn-gifting, #dailyQuests {margin-bottom: 10px;}";
  32. css += "#dailyquests-panel, .agario-shop-panel, #giftButton {display: none !important;}";
  33.  
  34. /* Center Options */
  35. css += "#tags-container {display: none;} #options {margin-left: 25px;}";
  36. var spans = document.getElementById("options").getElementsByTagName("span");
  37. for(var span of spans) {
  38. if(span.textContent == "Show Online Status") {
  39. span.textContent = "Show Online";
  40. }
  41. }
  42.  
  43. /* 'f' Key Toggles Fullscreen */
  44. function skipBrowserInconsistencies(object, properties) {
  45. for (var property of properties) {
  46. if (object[property] !== undefined) {
  47. return object[property];
  48. }
  49. }
  50. throw new Error("Browser does not have any: " + properties.join(", "));
  51. }
  52. var fullscreen = skipBrowserInconsistencies(document.body,
  53. ["requestFullscreen", "webkitRequestFullscreen", "mozRequestFullScreen"]
  54. ).bind(document.body);
  55. var exitFullscreen = skipBrowserInconsistencies(document,
  56. ["exitFullscreen", "webkitExitFullscreen", "mozCancelFullScreen"]
  57. ).bind(document);
  58. var isFullscreen = function() {
  59. return skipBrowserInconsistencies(document,
  60. ["fullscreen", "webkitIsFullScreen", "mozFullScreen"]);
  61. };
  62. window.addEventListener("keydown", function(event) {
  63. if (event.keyCode == 70) {
  64. if (isFullscreen()) {
  65. exitFullscreen();
  66. } else {
  67. fullscreen();
  68. }
  69. }
  70. });
  71.  
  72. /* Mouse Controls */
  73. var speed = 50;
  74. var ejectDown = false;
  75. var canvas = document.getElementById("canvas");
  76. canvas.addEventListener("mousedown", function(event) {
  77. switch(event.which) {
  78. case 1:
  79. window.core.split();
  80. break;
  81. case 2:
  82. for(var n = 0; n < 4; n++) {
  83. setTimeout(window.core.split, n * speed);
  84. }
  85. break;
  86. case 3:
  87. ejectDown = true;
  88. eject();
  89. break;
  90. }
  91. });
  92. window.addEventListener("mouseup", function(event) {
  93. if (event.which == 3) {
  94. ejectDown = false;
  95. }
  96. });
  97. canvas.addEventListener("mousewheel", function(event) {
  98. canvas.dispatchEvent(new MouseEvent('mousemove', {'clientX': window.innerWidth/2, 'clientY': window.innerHeight/2}));
  99. });
  100. canvas.addEventListener("contextmenu", prevent);
  101. canvas.addEventListener("drag", prevent);
  102. function eject() {
  103. if (ejectDown) {
  104. window.core.eject();
  105. setTimeout(eject, speed);
  106. }
  107. }
  108. function prevent(event) {
  109. event.preventDefault();
  110. }
  111.  
  112. /* Arrow Keys */
  113. var keys = [37, 38, 39, 40];
  114. var keysDown = {};
  115. var directions = [-1, -1, 1, 1];
  116. document.addEventListener("keydown", keychange);
  117. document.addEventListener("keyup", keychange);
  118. function keychange() {
  119. if (keys.includes(event.keyCode)) {
  120. keysDown[event.keyCode] = event.type == "keydown";
  121. update();
  122. }
  123. }
  124. function update() {
  125. var moveEvent = new Event("mousemove");
  126. moveEvent.clientX = window.innerWidth / 2;
  127. moveEvent.clientY = window.innerHeight / 2;
  128. for (var n = 0; n < keys.length; n++) {
  129. if (keysDown[keys[n]]) {
  130. moveEvent["client" + ((n % 2 === 0) ? "X" : "Y")] += directions[n] * Math.min(window.innerWidth, window.innerHeight);
  131. }
  132. }
  133. document.getElementById("canvas").dispatchEvent(moveEvent);
  134. }
  135.  
  136. /* Add Music Player */
  137. var src = "http://www.youtube.com/embed/1-AODuJpCG4" + "?controls=0;";
  138. var player = document.createElement("div");
  139. player.className = "agario-panel agario-side-panel";
  140. player.style = "padding: 0px; width: 293px; height: 168px; margin-top: 5px;";
  141. player.innerHTML = '<iframe id="YTVideo" src="' +
  142. src + '" style="border: 0px; width: 100%; height: 100%;"></iframe>';
  143. document.getElementById("rightPanel").appendChild(player);
  144.  
  145. /* Add Acid Mode */
  146. var label = document.createElement("label");
  147. label.innerHTML = '<input type="checkbox" id="acidMode" style="margin-top: 1px"><span>Acid mode</span>';
  148. document.getElementById("options").appendChild(label);
  149. var checkbox = document.getElementById("acidMode");
  150. checkbox.addEventListener("click", function() {
  151. core.setAcid(checkbox.checked);
  152. });
  153.  
  154. /* Remove Video Ads */
  155. setTimeout(function() {
  156. initAdsController = function() {};
  157. requestAds = function() {
  158. MC.notifyFullscreenAdFinished();
  159. };
  160. onAdLoaded = function() {
  161. onDone();
  162. };
  163. }, 5000);
  164.  
  165. /* Ubuntu Font */
  166. css += "@import url('https://fonts.googleapis.com/css?family=Ubuntu');";
  167. document.body.style.setProperty("font-family", "'Ubuntu', sans-serif", "important");
  168.  
  169. /* Vertically center main panel */
  170. css += `
  171. #helloContainer {
  172. position: relative;
  173. top: 50% !important;
  174. transform: perspective(1px) translate(-50%, -50%) !important;
  175. display: inline-block !important;
  176. width: auto !important;
  177. }
  178. #leftPanel {
  179. margin: 0px;
  180. width: 222px;
  181. }
  182. `;
  183.  
  184. /* Always display settings and intructions, also move the login button */
  185. css += `
  186. #settings {
  187. display: block !important;
  188. }
  189. .btn-settings {
  190. display: none;
  191. }
  192. .btn-play-guest {
  193. width: 100%;
  194. margin: 0px !important;
  195. }
  196. .btn-play {
  197. width: 100% !important;
  198. margin: 0px !important;
  199. }
  200. .btn-login-play {
  201. width: 110px !important;
  202. float: right;
  203. }
  204. #instructions,
  205. #options,
  206. .text-muted,
  207. #mainPanel {
  208. cursor: default !important;
  209. }
  210. input,
  211. select {
  212. cursor: pointer !important;
  213. }
  214. `;
  215. document.getElementsByClassName("btn-spectate")[0].parentNode.
  216. appendChild(document.getElementsByClassName("btn-login-play")[0]).
  217. textContent = "Login";
  218.  
  219. /* Blurry Font Fix */
  220. css += "body {line-height: normal !important;}";
  221.  
  222. /* Darken Stuff */
  223. css += `
  224. select,
  225. .agario-panel,
  226. .shop-blocker,
  227. #blocker,
  228. #nick,
  229. footer,
  230. .progress,
  231. .party-token,
  232. .agario-profile-picture {
  233. background: black !important;
  234. color: white !important;
  235. border: 0px !important;
  236. border-radius: 0px !important;
  237. outline: 1px solid white !important;
  238. }
  239. span {
  240. color: white !important;
  241. }
  242. .party-icon-back {
  243. background: black !important;
  244. }
  245. .btn {
  246. border-radius: 0px;
  247. }
  248. `;
  249.  
  250. /* Hide Static Ads */
  251. css += `
  252. .agario-promo-container,
  253. #advertisement,
  254. .diep-cross,
  255. #promo-badge-container,
  256. #agario-web-incentive,
  257. #mcbanners-container,
  258. #adsBottom {
  259. display: none !important;
  260. }
  261. `;
  262.  
  263. /* Append CSS To DOM */
  264. var style = document.createElement("style");
  265. style.innerHTML = css;
  266. document.head.appendChild(style);
  267. })();