// ==UserScript==
// @name Gota.io Features by Donut
// @namespace https://www.youtube.com/channel/UCIpCflcKEN9YgaO9qDahpRg
// @version 1.001
// @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: "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.
// @match http://gota.io/web/*
// @author Donut
// @grant none
// @run-at document-end
// ==/UserScript==
(function(){
var styles = {
'.donut-features-table': {
'margin': 'auto',
'border-collapse': 'collapse'
},
'.donut-features-table th, .donut-features-table td:nth-child(2), .donut-features-table td:nth-child(3)': {
'text-align': 'center'
},
'.donut-features-table th, .donut-features-table td': {
'padding': '2px 8px'
},
'.donut-features-table input': {
'width': '100px',
'text-align': 'center'
},
'.donut-channel-link': {
'box-sizing': 'border-box',
'display': 'block',
'margin': '3px auto 0',
'padding': '4px 8px 4px 5.5px',
'width': '85px',
'height': '24px',
'color': '#fefefe',
'font-family': 'Arial, Helvetica, sans-serif',
'font-size': '12px',
'line-height': 'normal',
'text-align': 'center',
'text-decoration': 'none',
'background-color': '#e62117',
'border': 'solid 1px transparent',
'border-radius': '2px',
'white-space': 'nowrap',
'vertical-align': 'middle',
'box-shadow': '0 1px 0 rgba(0,0,0,0.05)'
},
'.donut-channel-link::before': {
'content': '""',
'position': 'relative',
'top': '-1px',
'display': 'inline-block',
'margin-right': '6px',
'width': '16px',
'height': '12px',
'background': 'no-repeat url(//s.ytimg.com/yts/imgbin/www-hitchhiker-vfl-Nn88d.png) -721px -88px',
'background-size': 'auto',
'vertical-align': 'middle'
},
'.donut-channel-link>span': {
'display': 'inline-block',
'-moz-box-sizing': 'border-box',
'box-sizing': 'border-box'
},
'.donut-channel-link:hover': {
'background-color': '#cc181e'
},
'.donut-channel-link:active': {
'background-color': '#b31217'
}
};
var style = document.createElement('style');
document.head.appendChild(style);
var stylesheet = style.sheet;
for (var selector in styles)
for (var property in styles[selector]) {
var value = styles[selector][property];
if (Array.isArray(value)) for (var i = 0; i < value.length; i++)
stylesheet.insertRule(selector + '{' + property + ':' + value[i] + ';' + '}', stylesheet.cssRules.length);
else stylesheet.insertRule(selector + '{' + property + ':' + value + ';' + '}', stylesheet.cssRules.length);
}
var bottom = document.getElementsByClassName('main-bottom')[0], stats = document.getElementsByClassName('main-bottom-stats')[0];
bottom.style.position = 'relative';
bottom.style.left = '-7px';
stats.style.width = '100%';
stats.style.height = '140px';
var btnTemplate = document.createElement('button');
btnTemplate.className = 'gota-btn bottom-btn';
btnTemplate.style.marginTop = '12px';
btnTemplate.style.color = 'white';
btnTemplate.style.backgroundColor = 'rgba(23,22,23,.9)';
var btn = btnTemplate.cloneNode();
btn.className = 'gota-btn bottom-btn';
btn.style.position = 'relative';
btn.style.left = '2px';
btn.style.padding = '4px 3px 3px';
btn.style.width = '100%';
btn.style.fontSize = '16px';
btn.innerText = 'Features by Donut';
btn.addEventListener('click', function() {
blackout.style.display = 'block';
});
document.getElementsByClassName('main-bottom-right')[0].appendChild(btn);
var blackout = document.createElement('div');
blackout.style.position = 'fixed';
blackout.style.top = '0';
blackout.style.right = '0';
blackout.style.bottom = '0';
blackout.style.left = '0';
blackout.style.display = 'none';
blackout.style.background = 'rgba(0,0,0,.5)';
blackout.style.zIndex = '100';
document.body.appendChild(blackout);
var win = document.createElement('div');
win.style.position = 'fixed';
win.style.top = '8%';
win.style.left = '50%';
win.style.padding = '15px';
win.style.color = 'white';
win.style.fontFamily = 'Arial, Helvetica, sans-serif';
win.style.fontSize = '16px';
win.style.lineHeight = '22px';
win.style.textAlign = 'center';
win.style.backgroundColor = 'rgb(14,14,14)';
win.style.border = 'solid 2px rgba(255,255,255,.2)';
win.style.transform = 'translateX(-50%)';
win.innerHTML = `<table class='donut-features-table'><tbody><tr><th>Feature</th><th>Default</th><th>Custom key</th></tr>
<tr><td>Freeze</td><td>S</td><td><input type="text" data-donut-feature="freeze"></td></tr>
<tr><td>Show/hide skins</td><td>K</td><td><input type="text" data-donut-feature="skins"></td></tr>
<tr><td>Show/hide names</td><td>N</td><td><input type="text" data-donut-feature="names"></td></tr>
<tr><td>Show/hide mass</td><td>M</td><td><input type="text" data-donut-feature="mass"></td></tr>
<tr><td>Show/hide food</td><td>F</td><td><input type="text" data-donut-feature="food"></td></tr>
<tr><td>Show/hide chat</td><td>H</td><td><input type="text" data-donut-feature="chat"></td></tr>
<tr><th colspan="3">Team Scrimmage</th>
<tr><td>Queue</td><td>Enter</td><td><input type="text" data-donut-feature="queue"></td></tr>
<tr><td>Leave a match</td><td>L</td><td><input type="text" data-donut-feature="leave"></td></tr></tbody></table>
<div style="padding-top:4px;">If you want to turn off a feature, type Delete.<br>You can support the developer by checking out<br>his YouTube channel:</div>
<a href="https://www.youtube.com/channel/UCIpCflcKEN9YgaO9qDahpRg" target="_blank" class="donut-channel-link"><span>YouTube</span></a>`;
blackout.appendChild(win);
var done = btnTemplate.cloneNode();
done.style.display = 'block';
done.style.margin = '12px auto 0';
done.innerText = 'Done';
done.addEventListener('click', function() {
blackout.style.display = 'none';
});
win.appendChild(done);
var keyCodes = {
8 : 'Backspace',
9 : 'Tab',
13 : 'Enter',
33 : 'Page Up',
34 : 'Page Down',
35 : 'End',
36 : 'Home',
37 : 'Left Arrow',
38 : 'Up Arrow',
39 : 'Right Arrow',
40 : 'Down Arrow',
48 : '0',
49 : '1',
50 : '2',
51 : '3',
52 : '4',
53 : '5',
54 : '6',
55 : '7',
56 : '8',
57 : '9',
65 : 'A',
66 : 'B',
67 : 'C',
68 : 'D',
69 : 'E',
70 : 'F',
71 : 'G',
72 : 'H',
73 : 'I',
74 : 'J',
75 : 'K',
76 : 'L',
77 : 'M',
78 : 'N',
79 : 'O',
80 : 'P',
81 : 'Q',
82 : 'R',
83 : 'S',
84 : 'T',
85 : 'U',
86 : 'V',
87 : 'W',
88 : 'X',
89 : 'Y',
90 : 'Z',
96 : 'Numpad 0',
97 : 'Numpad 1',
98 : 'Numpad 2',
99 : 'Numpad 3',
100 : 'Numpad 4',
101 : 'Numpad 5',
102 : 'Numpad 6',
103 : 'Numpad 7',
104 : 'Numpad 8',
105 : 'Numpad 9'
};
var keys, defaultKeys = {
freeze: 83,
skins: 75,
names: 78,
mass: 77,
food: 70,
chat: 72,
queue: 13,
leave: 76
};
var inputs = document.querySelectorAll('.donut-features-table input'), error = 'Gota.io Features by Donut: An error occurred. We had to reset your custom keys.';
function fillInputs() {
for (var i = 0; i < inputs.length; i++) {
var key = keys[inputs[i].dataset.donutFeature];
if (key === null) continue;
var value = keyCodes[keys[inputs[i].dataset.donutFeature]];
if (value) inputs[i].value = value;
else throw error;
}
}
try {
if (!localStorage['donut-keys']) throw error;
keys = JSON.parse(localStorage['donut-keys']);
fillInputs();
} catch (e) {
keys = defaultKeys;
console.error(error);
localStorage['donut-keys'] = JSON.stringify(keys);
fillInputs();
}
for (var j = 0; j < inputs.length; j++) {
inputs[j].addEventListener('keydown', function(e) {
e.preventDefault();
var key = e.which || e.keyCode || 0;
if (key == 46) {
this.value = '';
keys[this.dataset.donutFeature] = null;
localStorage['donut-keys'] = JSON.stringify(keys);
}
else if (key != keys[this.dataset.donutFeature] && key in keyCodes) {
this.value = keyCodes[key];
for (var k in keys) {
if (keys[k] == key) {
keys[k] = null;
for (var l = 0; l < inputs.length; l++) if (inputs[l].dataset.donutFeature == k) {
inputs[l].value = '';
break;
}
}
}
keys[this.dataset.donutFeature] = key;
localStorage['donut-keys'] = JSON.stringify(keys);
}
});
}
window.addEventListener('keydown', function(e) {
if (!e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey && document.activeElement.tagName != 'INPUT' && document.activeElement.tagName != 'TEXTAREA') switch (e.which || e.keyCode || 0) {
case keys.queue:
if (document.getElementById('scrimmage-btn-leave').style.display == 'block') $('#btn-leave-match').trigger('click');
else if (document.getElementById('main').style.display == 'none' && document.getElementById('main-scrimmage').style.display == 'block') $('#btn-queue').trigger('click');
else team2v2();
break;
case keys.food:
triggerCheckbox('cHideFood');
break;
case keys.chat:
triggerCheckbox('cHideChat');
break;
case keys.skins:
triggerCheckbox('cHideSkins');
break;
case keys.leave:
if (done2v2) {
var cp = document.getElementById('chat-panel'), hidden = cp.style.display == 'none';
if (hidden) {
cp.style.opacity = '0';
cp.style.display = 'block';
}
$('#chat-input').val('/leave').focus().trigger($.Event('keypress', {keyCode: 13, which: 13})).blur();
if (hidden) {
cp.style.display = 'none';
cp.style.opacity = '1';
}
}
break;
case keys.mass:
triggerCheckbox('cShowMass');
break;
case keys.names:
triggerCheckbox('cHideNames');
break;
case keys.freeze:
X = window.innerWidth/2;
Y = window.innerHeight/2;
$('canvas').trigger($.Event('mousemove', {clientX: X, clientY: Y}));
}
});
function triggerCheckbox(id) {
$('#' + id).prop('checked', !$('#' + id).prop('checked')).trigger('change');
}
var done2v2 = false;
document.getElementById('btn-play').addEventListener('click', function() {
if (document.getElementById('s_BETA').classList.contains('server-selected')) {
if (!done2v2) {
var interval = setInterval(function() {
if (document.getElementById('main-scrimmage').style.display == 'block' && document.getElementById('scrimmage-mode-select').options.selectedIndex >= 0) {
document.getElementById('scrimmage-mode-select').options.selectedIndex = 1;
$('#scrimmage-mode-select').trigger('change');
clearTimeout(timeout);
clearInterval(interval);
done2v2 = true;
}
}, 0), timeout = setTimeout(function() {
clearInterval(interval);
}, 10000);
}
} else done2v2 = false;
});
document.getElementById('btn-spec').addEventListener('click', function() {
if (!document.getElementById('s_BETA').classList.contains('server-selected')) done2v2 = false;
});
})();