Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.35 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Gota.io Features by Donut
  3. // @namespace https://www.youtube.com/channel/UCIpCflcKEN9YgaO9qDahpRg
  4. // @version 1.6.10
  5. // @description Hold down S to freeze. Press K to show/hide skins, N to show/hide names, M to show/hide mass, F to show/hide food, H to show/hide chat. For Team Scrimmage players: auto respawn in Team Scrimmage, "Team 2v2" is selected by default, press Enter to queue a match or leave a match that has ended, L to leave a match at any time. You can change the keys if you wish. You can also set custom keys for triple split, show/hide minimap, score panel, party panel, leaderboard, and auto decline party invites.
  6. // @match *://gota.io/web/*
  7. // @author Donut
  8. // @grant none
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. window.addEventListener('keydown', keydown);
  18.  
  19. var Width
  20. var Height
  21. //NumKeys : ON
  22. function keydown(event) {
  23. switch (event.keyCode) {
  24. case 101: //Num5 key freeze cell
  25. X = window.innerWidth / 2;
  26. Y = window.innerHeight / 2;
  27. $("canvas").trigger($.Event("mousemove", {clientX: X, clientY: Y}));
  28. break;
  29. case 100: //Num4 key left line
  30. X = window.innerWidth / 3;
  31. Y = window.innerHeight / 2;
  32. $("canvas").trigger($.Event("mousemove", {clientX: X, clientY: Y}));
  33. break;
  34. case 102: //Num6 key right line
  35. X = window.innerWidth / 1;
  36. Y = window.innerHeight / 2;
  37. $("canvas").trigger($.Event("mousemove", {clientX: X, clientY: Y}));
  38. break;
  39. case 98: //Num2 key down line
  40. X = window.innerWidth / 2;
  41. Y = window.innerHeight / 1;
  42. $("canvas").trigger($.Event("mousemove", {clientX: X, clientY: Y}));
  43. break;
  44. case 104: //Num8 key up line
  45. X = window.innerWidth / 2;
  46. Y = window.innerHeight / 3;
  47. $("canvas").trigger($.Event("mousemove", {clientX: X, clientY: Y}));
  48. break;
  49.  
  50. //NumKeys : OFF
  51.  
  52. // Direction Keys : ON
  53.  
  54. case 38: //Arrow Up key up line
  55. X = window.innerWidth / 2;
  56. Y = window.innerHeight / 3;
  57. $("canvas").trigger($.Event("mousemove", {clientX: X, clientY: Y}));
  58. break;
  59. case 40: //Arrow Down key down line
  60. X = window.innerWidth / 2;
  61. Y = window.innerHeight / 1;
  62. $("canvas").trigger($.Event("mousemove", {clientX: X, clientY: Y}));
  63. break;
  64. case 37: //Arrow Left key left line
  65. X = window.innerWidth / 3;
  66. Y = window.innerHeight / 2;
  67. $("canvas").trigger($.Event("mousemove", {clientX: X, clientY: Y}));
  68. break;
  69. case 39: //Arrow Right key right line
  70. X = window.innerWidth / 1;
  71. Y = window.innerHeight / 2;
  72. $("canvas").trigger($.Event("mousemove", {clientX: X, clientY: Y}));
  73. break;
  74. case 35: //End key freeze cell
  75. X = window.innerWidth / 2;
  76. Y = window.innerHeight / 2;
  77. $("canvas").trigger($.Event("mousemove", {clientX: X, clientY: Y}));
  78. break;
  79. //Direction Keys : OFF
  80.  
  81. //Specials Keys : ON
  82. case 12: //KeyPad Off to num5 key freeze cell
  83. X = window.innerWidth / 2;
  84. Y = window.innerHeight / 2;
  85. $("canvas").trigger($.Event("mousemove", {clientX: X, clientY: Y}));
  86. break;
  87. case 33: // Impossible Diagonal line split key Insert (Left top,bottom)
  88. X = window.innerWidth / 1.996;
  89. Y = window.innerHeight / 2.004;
  90. $("canvas").trigger($.Event("mousemove", {clientX: X, clientY: Y}));
  91. break;
  92. break;
  93. case 45: // Impossible Diagonal line split key Page Up (Right top,bottom)
  94. X = window.innerWidth / 2.004;
  95. Y = window.innerHeight / 2.004;
  96. $("canvas").trigger($.Event("mousemove", {clientX: X, clientY: Y}));
  97. break;
  98. };
  99. if (event.keyCode == 113) { // Gota.io Diagonal Line Split Press F2 key
  100. split();
  101. split();
  102. split();
  103. esc();
  104. setTimeout(esc, Math.random() * (1000)); //auto ESC menu off
  105.  
  106. function split() {
  107. $("body").trigger($.Event("keydown", { keyCode: 32}));
  108. $("body").trigger($.Event("keyup", { keyCode: 32}));
  109. }
  110. function esc() {
  111. $("body").trigger($.Event("keydown", { keyCode: 27}));
  112. //Specials Keys : OFF
  113.  
  114. //Train Line Controller By Kibol 1.0
  115.  
  116. }
  117. }
  118. }
  119.  
  120.  
  121.  
  122. (function(){
  123. if (window.top != window.self) return;
  124.  
  125. if (!('code' in KeyboardEvent.prototype)) {
  126. return alert("Sorry, your browser is incompatible with Gota.io Features by Donut. You're recommended to install the newest version of Google Chrome or Mozilla Firefox browsers.");
  127. }
  128.  
  129. function getVersionParts(v, validate = false) {
  130. var parts = v.split('.');
  131. if (validate) for (var i = 0; i < parts.length; i++) if (!/^\d+$/.test(parts[i])) return false;
  132. return parts;
  133. }
  134.  
  135. function compareVersions(v1, v2) {
  136. var v1parts = getVersionParts(v1), v2parts = getVersionParts(v2);
  137.  
  138. v1parts = v1parts.map(Number);
  139. v2parts = v2parts.map(Number);
  140.  
  141. while (v1parts.length < v2parts.length) v1parts.push(0);
  142. while (v2parts.length < v1parts.length) v2parts.push(0);
  143.  
  144. for (var i = 0; i < v1parts.length; ++i) {
  145. if (v1parts[i] > v2parts[i]) return 1;
  146. else if (v1parts[i] < v2parts[i]) return -1;
  147. }
  148. return 0;
  149. }
  150.  
  151. var importantUpdates = ['1.5.3', '1.6', '1.6.3'];
  152. importantUpdates.sort(compareVersions);
  153.  
  154. var version = '1.6.10', storageVersion = localStorage['donut-version'], notify = false;
  155. if (!storageVersion || !getVersionParts(storageVersion, true) || compareVersions(version, storageVersion) == 1 && (importantUpdates.lastIndexOf(version) >= 0 || compareVersions(importantUpdates[importantUpdates.length - 1], storageVersion) == 1)) notify = true;
  156. else localStorage['donut-version'] = version;
  157.  
  158. var styles = {
  159. '.donut-features-table': {
  160. 'margin': 'auto',
  161. 'width': 'max-content',
  162. 'border-collapse': 'collapse'
  163. },
  164. '.donut-features-table td:nth-child(1)': {
  165. 'text-align': 'left'
  166. },
  167. '.donut-features-table th, .donut-features-table td': {
  168. 'padding': '2px 8px'
  169. },
  170. '.donut-features-table input[type="text"]': {
  171. 'width': '100px',
  172. 'text-align': 'center'
  173. },
  174. '.donut-features-div': {
  175. 'margin': 'auto',
  176. 'padding-top': '4px',
  177. 'width': 'max-content'
  178. },
  179. '.donut-checkbox': {
  180. 'position': 'relative',
  181. 'top': '1px',
  182. 'margin': '0 5px'
  183. },
  184. '#donut-scrimmageMode': {
  185. 'box-sizing': 'content-box',
  186. 'padding': '1px 0',
  187. 'width': '104px'
  188. },
  189. '.donut-channel-link': {
  190. 'box-sizing': 'border-box',
  191. 'display': 'block',
  192. 'margin': '3px auto 0',
  193. 'padding': '4px 8px 4px 5.5px',
  194. 'width': '85px',
  195. 'height': '24px',
  196. 'color': '#fefefe',
  197. 'font-family': 'Arial, Helvetica, sans-serif',
  198. 'font-size': '12px',
  199. 'line-height': 'normal',
  200. 'text-align': 'center',
  201. 'text-decoration': 'none',
  202. 'background-color': '#e62117',
  203. 'border': 'solid 1px transparent',
  204. 'border-radius': '2px',
  205. 'white-space': 'nowrap',
  206. 'vertical-align': 'middle',
  207. 'box-shadow': '0 1px 0 rgba(0,0,0,0.05)'
  208. },
  209. '.donut-channel-link::before': {
  210. 'content': '""',
  211. 'position': 'relative',
  212. 'top': '-1px',
  213. 'display': 'inline-block',
  214. 'margin-right': '6px',
  215. 'width': '16px',
  216. 'height': '12px',
  217. 'background': 'no-repeat url(//s.ytimg.com/yts/imgbin/www-hitchhiker-vfl-Nn88d.png) -721px -88px',
  218. 'background-size': 'auto',
  219. 'vertical-align': 'middle'
  220. },
  221. '.donut-channel-link>span': {
  222. 'display': 'inline-block',
  223. '-moz-box-sizing': 'border-box',
  224. 'box-sizing': 'border-box'
  225. },
  226. '.donut-channel-link:hover': {
  227. 'background-color': '#cc181e'
  228. },
  229. '.donut-channel-link:active': {
  230. 'background-color': '#b31217'
  231. }
  232. };
  233.  
  234. if (notify) {
  235. styles['.donut-features-btn::before'] = {
  236. 'content': '"!"',
  237. 'position': 'absolute',
  238. 'top': '-6px',
  239. 'right': '-6px'
  240. };
  241. styles['.donut-features-btn::before, .donut-updated'] = {
  242. 'width': '12px',
  243. 'height': '12px',
  244. 'color': 'white',
  245. 'font-size': '11px',
  246. 'font-weight': 'bold',
  247. 'text-align': 'center',
  248. 'line-height': '12px',
  249. 'background-color': 'red',
  250. 'border-radius': '50%',
  251. 'overflow': 'hidden',
  252. '-webkit-user-select': 'none',
  253. '-moz-user-select': 'none',
  254. '-ms-user-select': 'none',
  255. 'user-select': 'none',
  256. 'display': 'inline-flex',
  257. 'align-items': 'center',
  258. 'justify-content': 'center'
  259. };
  260. styles['.donut-updated'] = {
  261. 'position': 'relative',
  262. 'top': '-1px',
  263. 'vertical-align': 'middle'
  264. };
  265. }
  266.  
  267. function insertRule(selector) {
  268. var rule = selector + '{';
  269. for (var property in styles[selector]) rule += property + ':' + styles[selector][property] + ';';
  270. rule += '}';
  271. stylesheet.insertRule(rule, stylesheet.cssRules.length);
  272. }
  273.  
  274. var style = document.createElement('style');
  275. document.head.appendChild(style);
  276. var stylesheet = style.sheet;
  277. for (var selector in styles) insertRule(selector);
  278.  
  279. var left = document.getElementsByClassName('main-bottom-left')[0], right = document.getElementsByClassName('main-bottom-right')[0], stats = document.getElementsByClassName('main-bottom-stats')[0];
  280. left.style.position = 'relative';
  281. left.style.left = '-3px';
  282. left.style.marginRight = '6px';
  283. right.style.display = 'flex';
  284. right.style.flexFlow = 'column wrap';
  285. right.style.justifyContent = 'space-between';
  286. right.firstElementChild.style.margin = '0 auto';
  287. stats.style.width = '155px';
  288. stats.style.height = '148px';
  289.  
  290. var btnTemplate = document.createElement('button');
  291. btnTemplate.className = 'gota-btn bottom-btn';
  292. btnTemplate.style.color = 'white';
  293. btnTemplate.style.backgroundColor = 'rgba(23,22,23,.9)';
  294.  
  295. var btn = btnTemplate.cloneNode();
  296. btn.className += ' donut-features-btn';
  297. btn.style.position = 'relative';
  298. btn.style.boxSizing = 'border-box';
  299. btn.style.padding = '0px 3px';
  300. btn.style.width = '100%';
  301. btn.style.height = '32px';
  302. btn.style.fontSize = '16px';
  303. btn.style.lineHeight = '16px';
  304. btn.style.whiteSpace = 'nowrap';
  305. btn.style.overflow = 'visible';
  306. btn.innerText = 'Features by Donut';
  307. btn.addEventListener('click', function() {
  308. blackout.style.opacity = '0';
  309. blackout.style.display = 'block';
  310. resize();
  311. blackout.style.opacity = '1';
  312. if (notify) {
  313. localStorage['donut-version'] = version;
  314. stylesheet.insertRule('.donut-features-btn::before{content:none;}', stylesheet.cssRules.length);
  315. }
  316. });
  317. document.getElementsByClassName('main-bottom-right')[0].appendChild(btn);
  318.  
  319. var blackout = document.createElement('div');
  320. blackout.style.position = 'fixed';
  321. blackout.style.top = '0';
  322. blackout.style.right = '0';
  323. blackout.style.bottom = '0';
  324. blackout.style.left = '0';
  325. blackout.style.display = 'none';
  326. blackout.style.background = 'rgba(0,0,0,.5)';
  327. blackout.style.overflow = 'auto';
  328. blackout.style.zIndex = '100';
  329. document.body.appendChild(blackout);
  330.  
  331. var win = document.createElement('div');
  332. win.style.position = 'absolute';
  333. win.style.top = '50%';
  334. win.style.left = '50%';
  335. win.style.margin = '0';
  336. win.style.padding = '15px';
  337. win.style.color = 'white';
  338. win.style.fontFamily = 'Arial, Helvetica, sans-serif';
  339. win.style.fontSize = '16px';
  340. win.style.lineHeight = '22px';
  341. win.style.textAlign = 'center';
  342. win.style.backgroundColor = 'rgb(14,14,14)';
  343. win.style.border = 'solid 2px rgba(255,255,255,.2)';
  344. win.style.borderRadius = '5px';
  345. win.style.transform = 'translate(-50%, -50%)';
  346. win.innerHTML = `<table class='donut-features-table'><tbody><tr><th>Feature</th><th>Default</th><th>Custom key</th></tr>
  347. <tr><td>Freeze</td><td>S</td><td><input type="text" spellcheck="false" data-donut-feature="freeze"></td></tr>
  348. <tr><td>Show/hide skins</td><td>K</td><td><input type="text" spellcheck="false" data-donut-feature="skins"></td></tr>
  349. <tr><td>Show/hide names</td><td>N</td><td><input type="text" spellcheck="false" data-donut-feature="names"></td></tr>
  350. <tr><td>Show/hide mass</td><td>M</td><td><input type="text" spellcheck="false" data-donut-feature="mass"></td></tr>
  351. <tr><td>Show/hide food</td><td>F</td><td><input type="text" spellcheck="false" data-donut-feature="food"></td></tr>
  352. <tr><td>Show/hide chat</td><td>H</td><td><input type="text" spellcheck="false" data-donut-feature="chat"></td></tr>
  353. <tr><td colspan="2">Triple split</td><td><input type="text" spellcheck="false" data-donut-feature="tripleSplit"></td></tr>
  354. <tr><td colspan="2">Show/hide minimap</td><td><input type="text" spellcheck="false" data-donut-feature="minimap"></td></tr>
  355. <tr><td colspan="2">Show/hide score panel</td><td><input type="text" spellcheck="false" data-donut-feature="scorePanel"></td></tr>
  356. <tr><td colspan="2">Show/hide party panel</td><td><input type="text" spellcheck="false" data-donut-feature="partyPanel"></td></tr>
  357. <tr><td colspan="2">Show/hide leaderboard</td><td><input type="text" spellcheck="false" data-donut-feature="leaderboard"></td></tr>
  358. <tr><td colspan="2" style="padding-right:32px;">Toggle <em>Decline party invites</em></td><td><input type="text" spellcheck="false" data-donut-feature="autoDecline"></td></tr>
  359. <tr><td colspan="2">Toggle <em>Auto respawn</em></td><td><input type="text" spellcheck="false" data-donut-feature="autoRespawn"></td></tr>
  360. <tr><th colspan="3">Team Scrimmage</th>
  361. <tr><td>Queue</td><td>Enter</td><td><input type="text" spellcheck="false" data-donut-feature="queue"></td></tr>
  362. <tr><td>Leave a match</td><td>L</td><td><input type="text" spellcheck="false" data-donut-feature="leave"></td></tr></tbody></table>
  363. <div class="donut-features-div">You should only use the <em>Leave a match</em> hotkey<br>when playing with random teammates.<br>If you want to disable a hotkey, type Delete.</div>
  364. <div class="donut-features-div"><label><input type="checkbox" class="donut-checkbox" id="donut-hideScorePanel" data-donut-feature="hideScorePanel">Hide Score Panel</label><br>
  365. <label><input type="checkbox" class="donut-checkbox" id="donut-hidePartyPanel" data-donut-feature="hidePartyPanel">Hide Party Panel</label><br>
  366. <label><input type="checkbox" class="donut-checkbox" id="donut-hideLeaderboard" data-donut-feature="hideLeaderboard">Hide Leaderboard</label><br>
  367. <label><input type="checkbox" class="donut-checkbox" id="donut-scrimmageAutoRespawn" data-donut-feature="scrimmageAutoRespawn">Scrimmage Auto Respawn</label><br>
  368. <label><input type="checkbox" class="donut-checkbox" id="donut-startWithScrimmage" data-donut-feature="startWithScrimmage">Join Team Scrimmage as I open the game</label><br>
  369. <label><input type="checkbox" class="donut-checkbox" id="donut-leaveExperimental" data-donut-feature="leaveExperimental">Use my <em>Leave a match</em> hotkey to leave<br>my team in the other gamemodes</label></div>
  370. <div class="donut-features-div">Team Scrimmage Default: <select id="donut-scrimmageMode" data-donut-feature="scrimmageMode"><option value="0">Team 6v6</option><option value="1">Team 2v2</option><option value="2">Team 2v2 [MegaSplit]</option><option value="3">Duel 1v1</option></select></div>
  371. <div class="donut-features-div">You can support the developer by checking out<br>his YouTube channel:</div>
  372. <a href="https://www.youtube.com/channel/UCIpCflcKEN9YgaO9qDahpRg" target="_blank" class="donut-channel-link"><span>YouTube</span></a>`;
  373. if (notify && storageVersion) {
  374. if (compareVersions(storageVersion, '1.6') < 0) win.innerHTML = `<div class="donut-features-div" style="padding:0 0 4px 0;">Now you can use any key of your keyboard as<br>a hotkey, and select your <em>Leave a match</em> hotkey<br>to be used to leave a party in Experimental<br>(disabled by default, scroll down to enable).</div>` + win.innerHTML;
  375. if (compareVersions(storageVersion, '1.6.3') < 0) win.innerHTML = `<div class="donut-features-div" style="padding:0 0 4px 0;">Now you can select the default Scrimmage mode.</div>` + win.innerHTML;
  376. }
  377. blackout.appendChild(win);
  378.  
  379. function resize() {
  380. if (blackout.style.display == 'block') {
  381. if (window.innerHeight < win.offsetHeight + 20) {
  382. win.style.top = '0';
  383. win.style.margin = '10px';
  384. win.style.transform = 'translate(-50%, 0%)';
  385. } else {
  386. win.style.top = '50%';
  387. win.style.margin = '0';
  388. win.style.transform = 'translate(-50%, -50%)';
  389. }
  390. }
  391. }
  392. window.addEventListener('resize', resize);
  393.  
  394. document.addEventListener('click', function(e) {
  395. if (blackout.style.display == 'block' && e.target != win && !win.contains(e.target)) blackout.style.display = 'none';
  396. }, true);
  397.  
  398. var done = btnTemplate.cloneNode();
  399. done.style.display = 'block';
  400. done.style.margin = '12px auto 0';
  401. done.innerText = 'Done';
  402. done.addEventListener('click', function() {
  403. blackout.style.display = 'none';
  404. });
  405. win.appendChild(done);
  406.  
  407. var processedKeyCodes = {
  408. Escape: 'Esc',
  409. Minus: '-',
  410. Equal: '=',
  411. BracketLeft: '[',
  412. BracketRight: ']',
  413. Control: 'Ctrl',
  414. Semicolon: ';',
  415. Quote: "'",
  416. Backquote: '`',
  417. Backslash: '\\',
  418. Comma: ',',
  419. Period: '.',
  420. Slash: '/',
  421. NumpadMultiply: 'Numpad *',
  422. CapsLock: 'Caps Lock',
  423. ScrollLock: 'Scroll Lock',
  424. Numpad7: 'Numpad 7',
  425. Numpad8: 'Numpad 8',
  426. Numpad9: 'Numpad 9',
  427. NumpadSubtract: 'Numpad -',
  428. Numpad4: 'Numpad 4',
  429. Numpad5: 'Numpad 5',
  430. Numpad6: 'Numpad 6',
  431. NumpadAdd: 'Numpad +',
  432. Numpad1: 'Numpad 1',
  433. Numpad2: 'Numpad 2',
  434. Numpad3: 'Numpad 3',
  435. Numpad0: 'Numpad 0',
  436. NumpadDecimal: 'Numpad .',
  437. NumpadEqual: 'Numpad =',
  438. NumpadEnter: 'Enter',
  439. NumpadDivide: 'Numpad /',
  440. NumLock: 'Num Lock',
  441. ArrowUp: 'Arrow Up',
  442. PageUp: 'Page Up',
  443. ArrowLeft: 'Arrow Left',
  444. ArrowRight: 'Arrow Right',
  445. ArrowDown: 'Arrow Down',
  446. PageDown: 'Page Down',
  447. Meta: 'Win / \u2318',
  448. OS: 'Win / \u2318'
  449. };
  450.  
  451. function processKeyCode(code) {
  452. if (code.indexOf('Arrow') && code.indexOf('Bracket')) code = code.replace(/Key|Digit|Left|Right/, '');
  453. if (code in processedKeyCodes) return processedKeyCodes[code];
  454. return code;
  455. }
  456.  
  457. var keyCodes = {
  458. 8: 'Backspace',
  459. 9: 'Tab',
  460. 13: 'Enter',
  461. 33: 'Page Up',
  462. 34: 'Page Down',
  463. 35: 'End',
  464. 36: 'Home',
  465. 37: 'Arrow Left',
  466. 38: 'Arrow Up',
  467. 39: 'Arrow Right',
  468. 40: 'Arrow Down',
  469. 48: '0',
  470. 49: '1',
  471. 50: '2',
  472. 51: '3',
  473. 52: '4',
  474. 53: '5',
  475. 54: '6',
  476. 55: '7',
  477. 56: '8',
  478. 57: '9',
  479. 65: 'A',
  480. 66: 'B',
  481. 67: 'C',
  482. 68: 'D',
  483. 69: 'E',
  484. 70: 'F',
  485. 71: 'G',
  486. 72: 'H',
  487. 73: 'I',
  488. 74: 'J',
  489. 75: 'K',
  490. 76: 'L',
  491. 77: 'M',
  492. 78: 'N',
  493. 79: 'O',
  494. 80: 'P',
  495. 81: 'Q',
  496. 82: 'R',
  497. 83: 'S',
  498. 84: 'T',
  499. 85: 'U',
  500. 86: 'V',
  501. 87: 'W',
  502. 88: 'X',
  503. 89: 'Y',
  504. 90: 'Z',
  505. 96: 'Numpad 0',
  506. 97: 'Numpad 1',
  507. 98: 'Numpad 2',
  508. 99: 'Numpad 3',
  509. 100: 'Numpad 4',
  510. 101: 'Numpad 5',
  511. 102: 'Numpad 6',
  512. 103: 'Numpad 7',
  513. 104: 'Numpad 8',
  514. 105: 'Numpad 9'
  515. };
  516.  
  517. var defaultKeys = {
  518. freeze: 'S',
  519. skins: 'K',
  520. names: 'N',
  521. mass: 'M',
  522. food: 'F',
  523. chat: 'H',
  524. tripleSplit: null,
  525. minimap: null,
  526. scorePanel: null,
  527. partyPanel: null,
  528. leaderboard: null,
  529. autoDecline: null,
  530. autoRespawn: null,
  531. queue: 'Enter',
  532. leave: 'L'
  533. };
  534.  
  535. var inputs = document.querySelectorAll('.donut-features-table input[type="text"][data-donut-feature]'), errorKeys = 'Gota.io Features by Donut: An error occurred. We had to reset your custom keys.';
  536. function fillInputs(keys) {
  537. for (var i = 0; i < inputs.length; i++) {
  538. var feature = inputs[i].dataset.donutFeature, key = keys[feature];
  539. if (typeof key == 'undefined' && feature in defaultKeys) {
  540. key = keys[feature] = defaultKeys[feature];
  541. localStorage['donut-keys'] = JSON.stringify(keys);
  542. } else if (typeof(key) == 'number') {
  543. key = keys[feature] = key in keyCodes ? keyCodes[key] : defaultKeys[feature];
  544. localStorage['donut-keys'] = JSON.stringify(keys);
  545. }
  546. if (key === null) continue;
  547. inputs[i].value = key;
  548. }
  549. }
  550.  
  551. function tryLocalStorage(index, defaultObj, func, error) {
  552. var obj; index = 'donut-' + index;
  553. try {
  554. if (!localStorage[index]) throw null;
  555. obj = JSON.parse(localStorage[index]);
  556. if (func) func(obj);
  557. } catch (e) {
  558. obj = JSON.parse(JSON.stringify(defaultObj));
  559. if (e && error) console.error(error);
  560. localStorage[index] = JSON.stringify(obj);
  561. if (func) func(obj);
  562. }
  563. return obj;
  564. }
  565.  
  566. var keys = tryLocalStorage('keys', defaultKeys, fillInputs, errorKeys);
  567.  
  568. function handleInputKeydown(e) {
  569. e.preventDefault();
  570. var feature = this.dataset.donutFeature, code = processKeyCode(e.code);
  571. if (code) {
  572. if (code == 'Delete') {
  573. this.value = '';
  574. keys[feature] = null;
  575. localStorage['donut-keys'] = JSON.stringify(keys);
  576. } else if (code != keys[feature] && code != 'Unidentified') {
  577. for (var k in keys) {
  578. if (keys[k] == code) {
  579. keys[k] = null;
  580. for (var l = 0; l < inputs.length; l++) {
  581. if (inputs[l].dataset.donutFeature == k) {
  582. inputs[l].value = '';
  583. break;
  584. }
  585. }
  586. }
  587. }
  588. this.value = keys[feature] = code;
  589. localStorage['donut-keys'] = JSON.stringify(keys);
  590. }
  591. }
  592. }
  593.  
  594. for (var j = 0; j < inputs.length; j++) {
  595. inputs[j].addEventListener('keydown', handleInputKeydown);
  596. }
  597.  
  598. var cache = tryLocalStorage('cache', {});
  599.  
  600. function selectOption(id) {
  601. var select = document.getElementById(id), index = select.selectedIndex;
  602. select.selectedIndex = (index + (index == 1) + 1) % select.options.length;
  603. $(select).trigger('change');
  604. }
  605.  
  606. function triggerCheckbox(id) {
  607. $('#' + id).prop('checked', !$('#' + id).prop('checked')).trigger('change');
  608. }
  609.  
  610. function triggerDonutCheckbox(id) {
  611. var checkbox = document.getElementById(id);
  612. checkbox.checked = !checkbox.checked;
  613. checkbox.dispatchEvent(new Event('change'));
  614. }
  615.  
  616. function fadeOutMain() {
  617. if (document.getElementById('main').style.display == 'block') window.onkeydown({keyCode: 27, which: 27});
  618. }
  619.  
  620. var alertWin = win.cloneNode();
  621. alertWin.style.top = '10px';
  622. alertWin.style.display = 'none';
  623. alertWin.style.lineHeight = '19px';
  624. alertWin.style.backgroundColor = 'rgba(23,23,23,.9)';
  625. alertWin.style.boxShadow = '0 2px 3px rgba(0,0,0,.25)';
  626. alertWin.style.transform = 'translate(-50%, 0%)';
  627. alertWin.style.zIndex = '3';
  628. document.body.appendChild(alertWin);
  629.  
  630. var alertFadeOutTimer = 0;
  631. function Alert(html, timeout) {
  632. alertWin.innerHTML = html;
  633. $(alertWin).fadeIn(500);
  634. if (alertFadeOutTimer) clearTimeout(alertFadeOutTimer);
  635. alertFadeOutTimer = setTimeout(function() {
  636. $(alertWin).fadeOut(500);
  637. alertFadeOutTimer = 0;
  638. }, timeout);
  639. }
  640.  
  641. var frozen = false, x = 0, y = 0, originalMousemove;
  642. setTimeout(function delay() {
  643. if (window.onmousemove) {
  644. originalMousemove = window.onmousemove;
  645. window.onmousemove = function(e) {
  646. x = e.clientX; y = e.clientY;
  647. if (!frozen) originalMousemove(e);
  648. };
  649. } else {
  650. setTimeout(delay, 200);
  651. }
  652. }, 200);
  653.  
  654. window.addEventListener('keydown', function(e) {
  655. if (e.code == undefined) return;
  656. var code = processKeyCode(e.code), modifier = false;
  657. if ((code == 'Alt' && !e.ctrlKey && !e.metaKey && !e.shiftKey) || (code == 'Ctrl' && !e.altKey && !e.metaKey && !e.shiftKey) || (code == 'Win / \u2318' && !e.altKey && !e.ctrlKey && !e.shiftKey) || (code == 'Shift' && !e.altKey && !e.ctrlKey && !e.metaKey)) modifier = true;
  658. if (modifier || !e.altKey && !e.ctrlKey && !e.metaKey) {
  659. if (!modifier) {
  660. var key = e.which || e.keyCode || 0;
  661. if (key == 13 && document.activeElement === document.getElementById('name-box')) team2v2();
  662. else if (key == 27) {
  663. if (!firstEscape) firstEscape = true;
  664. if (alertWin.offsetHeight) $(alertWin).fadeOut(500);
  665. }
  666. }
  667. if ((modifier || !e.shiftKey) && document.activeElement.tagName != 'INPUT' && document.activeElement.tagName != 'TEXTAREA') {
  668. switch (code) {
  669. case keys.freeze:
  670. if (originalMousemove) {
  671. var X = window.innerWidth/2;
  672. var Y = window.innerHeight/2;
  673. originalMousemove({clientX: X, clientY: Y});
  674. frozen = true;
  675. }
  676. break;
  677. case keys.skins:
  678. selectOption('sShowSkins');
  679. break;
  680. case keys.names:
  681. selectOption('sShowNames');
  682. break;
  683. case keys.mass:
  684. triggerCheckbox('cShowMass');
  685. break;
  686. case keys.food:
  687. triggerCheckbox('cHideFood');
  688. break;
  689. case keys.chat:
  690. triggerCheckbox('cHideChat');
  691. break;
  692. case keys.tripleSplit:
  693. for (var i = 0; i < 3; i++) $(window).trigger($.Event('keydown', {keyCode: 32, which: 32}));
  694. break;
  695. case keys.minimap:
  696. triggerCheckbox('cHideMinimap');
  697. break;
  698. case keys.scorePanel:
  699. triggerDonutCheckbox('donut-hideScorePanel');
  700. break;
  701. case keys.partyPanel:
  702. triggerDonutCheckbox('donut-hidePartyPanel');
  703. break;
  704. case keys.leaderboard:
  705. triggerDonutCheckbox('donut-hideLeaderboard');
  706. break;
  707. case keys.autoDecline:
  708. triggerCheckbox('cAutoDecline');
  709. Alert('Auto Decline Party Invites: <strong>' + (document.getElementById('cAutoDecline').checked ? 'On' : 'Off') + '</strong>', 2500);
  710. break;
  711. case keys.autoRespawn:
  712. var id = done2v2 ? 'donut-scrimmageAutoRespawn' : 'cAutoRespawn';
  713. if (done2v2) triggerDonutCheckbox(id);
  714. else triggerCheckbox(id);
  715. Alert('Auto Respawn' + (done2v2 ? ' in Team Scrimmage' : '') + ': <strong>' + (document.getElementById(id).checked ? 'On' : 'Off') + '</strong>', 2500);
  716. break;
  717. case keys.queue:
  718. if (document.getElementById('scrimmage-btn-leave').style.display == 'block') $('#btn-leave-match').trigger('click');
  719. else if (document.getElementById('main-scrimmage').style.display == 'block') $('#btn-queue').trigger('click');
  720. fadeOutMain();
  721. break;
  722. case keys.leave:
  723. if (switches.leaveExperimental || scrimmage) {
  724. var cp = document.getElementById('chat-panel'), hidden = cp.style.display == 'none';
  725. if (hidden) {
  726. cp.style.opacity = '0';
  727. cp.style.display = 'block';
  728. }
  729. $('#chat-input').val('/leave').focus().trigger($.Event('keyup', {keyCode: 13, which: 13})).blur();
  730. scrimmage = false;
  731. if (hidden) {
  732. cp.style.display = 'none';
  733. cp.style.opacity = '1';
  734. }
  735. fadeOutMain();
  736. }
  737. }
  738. }
  739. }
  740. });
  741.  
  742. window.addEventListener('keyup', function(e) {
  743. if (originalMousemove && e.code && processKeyCode(e.code) == keys.freeze && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey && document.activeElement.tagName != 'INPUT' && document.activeElement.tagName != 'TEXTAREA') {
  744. frozen = false;
  745. originalMousemove({clientX: x, clientY: y});
  746. }
  747. });
  748.  
  749. var defaultSwitches = {
  750. hideScorePanel: false,
  751. hidePartyPanel: false,
  752. hideLeaderboard: false,
  753. scrimmageAutoRespawn: true,
  754. startWithScrimmage: false,
  755. leaveExperimental: false
  756. };
  757.  
  758. var checkboxes = document.getElementsByClassName('donut-checkbox'), errorSwitches = 'Gota.io Features by Donut: An error occurred. We had to reset your settings.';
  759. function fillCheckboxes(switches) {
  760. for (var i = 0; i < checkboxes.length; i++) {
  761. var feature = checkboxes[i].dataset.donutFeature, Switch = switches[feature];
  762. if (typeof Switch == 'undefined' && feature in defaultSwitches) {
  763. Switch = switches[feature] = defaultSwitches[feature];
  764. localStorage['donut-switches'] = JSON.stringify(switches);
  765. }
  766. if (typeof Switch == 'boolean') checkboxes[i].checked = Switch;
  767. else throw errorSwitches;
  768. }
  769. }
  770.  
  771. var switches = tryLocalStorage('switches', defaultSwitches, fillCheckboxes, errorSwitches);
  772.  
  773. var anchorObd = document.querySelector('.options-table>thead:nth-of-type(2)'), obd = anchorObd.cloneNode(true);
  774. obd.firstElementChild.firstElementChild.textContent = 'Options by Donut';
  775. anchorObd.parentNode.insertBefore(obd, anchorObd);
  776.  
  777. var tbody = document.createElement('tbody');
  778. anchorObd.parentNode.insertBefore(tbody, anchorObd);
  779.  
  780. function duplicatedCheckbox(feature, text) {
  781. var td = document.createElement('td');
  782. td.colSpan = '2';
  783. td.style.position = 'relative';
  784. td.style.paddingRight = '22px';
  785. td.textContent = text;
  786.  
  787. var checkbox = document.createElement('input');
  788. checkbox.type = 'checkbox';
  789. checkbox.className = 'checkbox-options';
  790. checkbox.dataset.donutFeature = feature;
  791. checkbox.style.position = 'absolute';
  792. checkbox.style.top = '1px';
  793. checkbox.style.right = '1px';
  794. td.appendChild(checkbox);
  795.  
  796. var tr = document.createElement('tr');
  797. tr.appendChild(td);
  798. tbody.appendChild(tr);
  799.  
  800. return checkbox;
  801. }
  802.  
  803. for (var feature in defaultSwitches) {
  804. var bro = document.querySelector('.donut-checkbox[data-donut-feature="' + feature + '"]'), text = (feature == 'startWithScrimmage' ? 'Join Scrimmage as I open the game' : bro.parentNode.innerText).replace('\n', ' ');
  805. duplicatedCheckbox(feature, text).checked = switches[feature];
  806. }
  807.  
  808. function handleCheckboxChange(e) {
  809. var feature = this.dataset.donutFeature;
  810. switches[feature] = this.checked;
  811. localStorage['donut-switches'] = JSON.stringify(switches);
  812. document.querySelector('input[type="checkbox"][data-donut-feature="' + feature + '"]' + (this.classList.contains('donut-checkbox') ? ':not(.donut-checkbox)' : '.donut-checkbox')).checked = this.checked;
  813. switch (feature) {
  814. case 'hideScorePanel':
  815. if (this.checked) hideScorePanel();
  816. else {
  817. document.getElementById('party-panel').style.top = document.getElementById('score-panel').offsetHeight + 20 + 'px';
  818. document.getElementById('score-panel').style.opacity = '1';
  819. }
  820. break;
  821. case 'hidePartyPanel':
  822. visibility('party-panel', !this.checked);
  823. break;
  824. case 'hideLeaderboard':
  825. visibility('leaderboard-panel', !this.checked);
  826. break;
  827. case 'scrimmageAutoRespawn':
  828. if (this.checked && scrimmage) scrimRespawn();
  829. }
  830. }
  831.  
  832. checkboxes = document.querySelectorAll('input[type="checkbox"][data-donut-feature]');
  833. for (var k = 0; k < checkboxes.length; k++) {
  834. checkboxes[k].addEventListener('change', handleCheckboxChange);
  835. }
  836.  
  837. function hideScorePanel() {
  838. document.getElementById('score-panel').style.opacity = '0';
  839. document.getElementById('party-panel').style.top = '10px';
  840. }
  841. if (switches.hideScorePanel) hideScorePanel();
  842.  
  843. document.getElementById('cHideId').addEventListener('change', function() {
  844. if (document.getElementById('score-panel').style.opacity == '1') document.getElementById('party-panel').style.top = document.getElementById('score-panel').offsetHeight + 20 + 'px';
  845. });
  846.  
  847. function visibility(id, visible) {
  848. document.getElementById(id).style.visibility = visible ? 'visible' : 'hidden';
  849. }
  850. if (switches.hideLeaderboard) visibility('leaderboard-panel', false);
  851. if (switches.hidePartyPanel) visibility('party-panel', false);
  852.  
  853. var defaultOptions = {
  854. scrimmageMode: '2'
  855. };
  856.  
  857. var selects = [document.getElementById('donut-scrimmageMode')];
  858. function fillSelects(options) {
  859. for (var i = 0; i < selects.length; i++) {
  860. var feature = selects[i].dataset.donutFeature, option = options[feature];
  861. if (typeof option == 'undefined' && feature in defaultOptions) {
  862. option = options[feature] = defaultOptions[feature];
  863. localStorage['donut-options'] = JSON.stringify(options);
  864. }
  865. var el = document.querySelector('[data-donut-feature="' + feature + '"] option[value="' + option + '"]');
  866. if (el) selects[i].selectedIndex = el.index;
  867. else throw null;
  868. }
  869. }
  870.  
  871. var options = tryLocalStorage('options', defaultOptions, fillSelects);
  872.  
  873. for (var l = 0; l < selects.length; l++) {
  874. selects[l].addEventListener('change', function(e) {
  875. var feature = this.dataset.donutFeature;
  876. options[feature] = this.options[this.selectedIndex].value;
  877. localStorage['donut-options'] = JSON.stringify(options);
  878. });
  879. }
  880.  
  881. var scrimmage = false, respawnCheckInterval = 0, respawnTimer = 0;
  882. document.getElementById('btn-queue').addEventListener('click', function() {
  883. scrimmage = true;
  884. if (switches.scrimmageAutoRespawn) scrimRespawn();
  885. });
  886.  
  887. function scrimmageFalse() {
  888. scrimmage = false;
  889. if (respawnTimer) {
  890. clearTimeout(respawnTimer);
  891. respawnTimer = respawnCheckInterval = 0;
  892. }
  893. }
  894. document.getElementById('btn-leave-match').addEventListener('click', scrimmageFalse);
  895.  
  896. function scrimRespawn() {
  897. var cells = document.getElementById('playerCells'), cellsNum = parseInt(cells.innerText, 10);
  898. if (respawnCheckInterval) clearInterval(respawnCheckInterval);
  899. respawnCheckInterval = setInterval(function() {
  900. if (switches.scrimmageAutoRespawn && scrimmage) {
  901. var temp = parseInt(cells.innerText, 10);
  902. if (temp != cellsNum) {
  903. cellsNum = temp;
  904. if (cellsNum === 0) {
  905. if (document.getElementById('main-scrimmage').style.display == 'none') {
  906. respawnTimer = setTimeout(function() {
  907. if (switches.scrimmageAutoRespawn && scrimmage) {
  908. $('#btn-play').trigger('click');
  909. respawnTimer = 0;
  910. scrimRespawn();
  911. }
  912. }, 10000);
  913. }
  914. clearInterval(respawnCheckInterval);
  915. respawnCheckInterval = 0;
  916. }
  917. }
  918. } else {
  919. clearInterval(respawnCheckInterval);
  920. respawnCheckInterval = 0;
  921. }
  922. }, 500);
  923. }
  924.  
  925. var firstEscape = false;
  926. function startScrimmage() {
  927. var region = document.getElementsByClassName('server-active')[0].getAttribute('region');
  928. var id = region == 'eu' ? 's_Beta' : region == 'na' ? 's_Jet' : 's_Citrus';
  929. var interval = setInterval(function() {
  930. if (document.getElementById(id) && document.getElementsByClassName('server-selected').length) {
  931. $('#' + id).trigger('click');
  932. $('#btn-play').trigger('click');
  933. setTimeout(function() {
  934. if (!firstEscape && !done2v2) Alert('It looks like the server is not responding.<br>You may want to press <strong>Esc</strong> to go back to the game menu.', 20000);
  935. }, 5000);
  936. clearInterval(interval);
  937. }
  938. }, 100);
  939. }
  940. if (switches.startWithScrimmage) startScrimmage();
  941.  
  942. var lastScrimmageServer = null;
  943. function isTeamScrimmage() {
  944. var servers = ['Beta', 'Jet', 'Citrus'];
  945. for (var i = 0; i < servers.length; i++) if (document.getElementById('s_' + servers[i]).classList.contains('server-selected')) return servers[i];
  946. return false;
  947. }
  948.  
  949. var done2v2 = false, checkigTean2v2 = false;
  950. function team2v2() {
  951. if (!checkigTean2v2) {
  952. var scrimmageServer = isTeamScrimmage();
  953. if (scrimmageServer) {
  954. if (!done2v2 || scrimmageServer != lastScrimmageServer) {
  955. lastScrimmageServer = scrimmageServer;
  956. checkigTean2v2 = true;
  957. var interval = setInterval(function() {
  958. if (document.getElementById('main-scrimmage').style.display == 'block' && document.getElementById('scrimmage-mode-select').selectedIndex === 0) {
  959. document.getElementById('scrimmage-mode-select').selectedIndex = options.scrimmageMode;
  960. $('#scrimmage-mode-select').trigger('change');
  961. clearTimeout(timeout);
  962. clearInterval(interval);
  963. done2v2 = true;
  964. checkigTean2v2 = false;
  965. if (switches.startWithScrimmage && alertWin.offsetHeight) alertWin.style.display = 'none';
  966. }
  967. }, 100), timeout = setTimeout(function() {
  968. clearInterval(interval);
  969. checkigTean2v2 = false;
  970. }, 25000);
  971. }
  972. } else {
  973. scrimmageFalse();
  974. done2v2 = false;
  975. }
  976. }
  977. }
  978.  
  979. document.getElementById('btn-play').addEventListener('click', team2v2);
  980. document.getElementById('btn-spec').addEventListener('click', team2v2);
  981.  
  982. var recaptcha = document.getElementById('recaptcha');
  983. if (recaptcha) recaptcha.style.display = 'none';
  984. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement