// ==UserScript==
// @name Agar.io auto respawn (evergreen)
// @namespace http://redd.it/3ut09g
// @description Auto respawn + Auto-save settings + Profiles + Macros + Reload server button + Spectate mode + more
// @author condoriano
// @include http://agar.io/*
// @include https://agar.io/*
// @version 16
// @grant none
// ==/UserScript==
var lastEdit = 1464841718717;
var respawnLoop = null, ejectorLoop = null, randomMoveLoop = null, clickCoinLoop = null;
var overlayClosed = false, spectatorMode = false;
var profileSettings = {};
var holdingKey = {};
var canvas = document.getElementById('canvas');
$(document).ready(function() {
window.onbeforeunload = function() { return 'Quit game?'; };
window.setAutoSpawn = function(e) {
if(e) { if(!respawnLoop) respawnLoop = setInterval(startGame, 1000); }
else { clearInterval(respawnLoop); respawnLoop = null; }
};
window.joinNewRoom = function() {
var s = $('#gamemode').val();
if(s == ':party') $('button[data-itr="create_party"]').click();
else {
MC.setGameMode(':party');
MC.setGameMode(s);
}
};
window.setSpectatorMode = function(e) { spectatorMode = e; };
window.setRandomMove = function(e) {
if(e) {
if(!randomMoveLoop) randomMoveLoop = setInterval(randomMove, $('#randommove_interval').val() * 1000);
$('#randommove_interval').removeAttr('disabled');
}
else {
clearInterval(randomMoveLoop); randomMoveLoop = null;
$('#randommove_interval').attr('disabled', 'disabled');
}
};
window.setAutoCoin = function(e) {
if(e) {
if(!clickCoinLoop) clickCoinLoop = setInterval(function() { $('#freeCoins').click(); }, $('#clickcoin_interval').val() * 60000);
$('#clickcoin_interval').removeAttr('disabled');
}
else {
clearInterval(clickCoinLoop); clickCoinLoop = null;
$('#clickcoin_interval').attr('disabled', 'disabled');
}
};
window.setProfile = function(x) {
if(x == null) x = 0;
$('#profiles a').eq(localStorage.getItem('activeprofile')).css({'background-color': '#222'});
$('#profiles a').eq(x).css({'background-color': '#D00'});
localStorage.setItem('activeprofile', x);
profileSettings = JSON.parse(localStorage.getItem('profile' + x));
var checkbox = $('#options input[type="checkbox"]');
if(profileSettings == null) {
profileSettings = {};
if(localStorage.getItem('nick') != null && x == 0) $('#nick').val(localStorage.getItem('nick'));
else $('#nick').val('ௌௌௌௌௌௌௌௌௌௌௌௌௌௌௌ');
$('#nick, #gamemode, #region, #quality').change();
checkbox.each(function() { if($(this).prop('checked') == true) $(this).change(); });
}
else {
$('#nick, #gamemode, #region, #quality, #randommove_interval, #clickcoin_interval').each(function() {
var itsID = $(this).attr('id')
if(profileSettings[itsID] != undefined) $(this).val(profileSettings[itsID]).change();
else {
if(itsID == 'randommove_interval') $(this).val('5').change();
else if(itsID == 'clickcoin_interval') $(this).val('10').change();
}
});
checkbox.each(function() {
if($(this).prop('checked') == true && profileSettings[$(this).next().attr('data-itr')] != true) $(this).click();
else if($(this).prop('checked') == false && profileSettings[$(this).next().attr('data-itr')] == true) $(this).click();
});
if($('#gamemode').val() == ':party') joinNewRoom();
}
};
window.toggleScriptInfo = function() { $('#infoPanel').fadeToggle(); };
window.toggleScriptInfoChangelog = function() { $('#infoPanel-content a').next().slideToggle(); };
$(document).on('keydown', function(evt) {
var key = evt.which || evt.keyCode;
var exKey = evt.ctrlKey || evt.shiftKey || evt.altKey;
//console.log(key + ' ' + exKey + ' (' + evt.ctrlKey + ' ' + evt.shiftKey + ' ' + evt.altKey + ')');
if($('#overlays').is(':hidden') && !exKey) {
if(key == 27) { // KEY_ESC
overlayClosed = false;
setTimeout(function() { $('button[data-itr="spectate"]').removeAttr('disabled'); }, 100);
}
else if(key == 69) { // KEY_E
if(!ejectorLoop) {
ejectorLoop = setInterval(function() { sendEject(); }, 50);
}
}
if(!holdingKey[key]) {
if(key == 82) { // KEY_R
setIntervalX(function() { sendEject(); }, 120, 7);
}
else if(key == 84) { // KEY_T
setIntervalX(function() { sendMitosis(); }, 60, 4);
}
else if(key == 83) { // KEY_S
var mEv = new MouseEvent('mousemove', {'clientX': window.innerWidth/2, 'clientY': window.innerHeight/2});
canvas.dispatchEvent(mEv);
}
else if(key == 67) { // KEY_C
var mEv = new MouseEvent('mousemove', {'screenX': window.innerWidth/2, 'screenY': window.innerHeight/2});
canvas.dispatchEvent(mEv);
}
else if(key == 86) { showPanels(2); } // KEY_V
else if(key == 66) { showPanels(1); } // KEY_B
else if(key == 78) { showPanels(3); } // KEY_N
else if(key == 77) { showPanels(4); } // KEY_M
else if(key == 188) { showPanels(5); } // KEY_,
}
holdingKey[key] = true;
}
});
$(document).on('keyup', function(evt) {
var key = evt.which || evt.keyCode
holdingKey[key] = false;
if(key == 69) { // KEY_E
clearInterval(ejectorLoop);
ejectorLoop = null;
}
});
editPanel();
hookOverlay();
setTimeout(applyConfig, 1500);
});
function editPanel() {
var btnGroup = $('#agario-main-buttons div').eq(0).children();
btnGroup.eq(1).css('width', '230px');
btnGroup.eq(2).css('width', '112px');
btnGroup.eq(3).css('width', '112px').after('<button style="height: 35px; display: block; float: right;" class="btn btn-success btn-refresh" onclick="joinNewRoom(); return false;"><i class="glyphicon glyphicon-refresh"></i></button>');
$('#helloContainer').css('height', '');
$('#adbg').parent().hide().css('visibility', 'hidden');
$('#agario-web-incentive a, .agario-promo').remove();
$('#connecting').css({'top': '13px', 'right': '185px', 'bottom': '', 'left': '', 'font-size': '13px'});
$('#connecting h2').css({'display': 'inline-block'}).after('<span id="connectingToInfo" style="position: absolute; top: 5px; right: 15px;"></span>');
$('#nick').attr('name', 'nick');
$('#quality').css({'margin': '6px 0px'});
setTimeout(function() { $('#___ytsubscribe_0').css({'width': '112px'})}, 12000);
$('button[data-itr="logout"]').replaceWith('<button class="btn btn-danger btn-logout" data-itr="logout">Logout</button>');
$('#options').append('<label style="margin-top: 10px; padding-top: 10px; border-top: 1px dashed #888; width: 282px;"><input type="checkbox" onchange="setAcid($(this).is(\':checked\'));"><span data-itr="option_acid_mode">Acid mode</span></label><label style="width: 282px;"><input type="checkbox" onchange="setAutoSpawn($(this).is(\':checked\'));"><span data-itr="option_auto_spawn">Auto respawn</span></label><label style="width: 282px;"><input type="checkbox" onchange="setSpectatorMode($(this).is(\':checked\'));"><span data-itr="option_spectator_mode">Spectate on join</span></label><label style="width: 282px; margin: 3px 0px;"><input type="checkbox" onchange="setRandomMove($(this).is(\':checked\'));"><span data-itr="option_random_move">Randomize movement</span><input id="randommove_interval" type="number" min="1" disabled="disabled" style="margin: 0px 5px; width: 60px;">sec</label><label style="width: 282px; margin: 5px 0px;"><input type="checkbox" onchange="setAutoCoin($(this).is(\':checked\'));"><span data-itr="option_auto_coin">Auto click hourly coin</span><input id="clickcoin_interval" type="number"c disabled="disabled" style="margin: 0px 3px; width: 60px;">min</label>');
$('#instructions center').after('<hr><div id="shortcuts" style="font-size: 85%;"><strong style="display: inline-block; width: 320px; text-align: center; padding-bottom: 10px;">Ingame Shortcuts</strong><br><span style="display: block; width: 160px; float: left;">E: Shoot mass cont.</span><span style="display: block; width: 160px; float: left;">V: Skin panel</span><span style="display: block; width: 160px; float: left;">R: Shoot mass 7 times</span><span style="display: block; width: 160px; float: left;">B: Shop panel</span><span style="display: block; width: 160px; float: left;">T: Split into 16 pieces</span><span style="display: block; width: 160px; float: left;">N: XP Boost panel</span><span style="display: block; width: 160px; float: left;">S: Stop movement</span><span style="display: block; width: 160px; float: left;">M: Mass Boost panel</span><span style="display: block; width: 160px; float: left;">C: Go to center of map</span><span style="display: block; width: 160px; float: left;">,: Free coins panel</span></div>');
$('#instructions center span[class="text-muted"] b').css({'background-color': '#333', 'color': '#EEE', 'padding': '1px 5px', 'border-radius': '3px'});
$('#instructions').append('<div id="script-info" style="font-size: 70%; float: right; margin: 23px 0px 6px 0px;">Script by condoriano. <a href="#" onclick="toggleScriptInfo(); return false;">More Info</a></div>');
$('#instructions').next().remove();
$('#nick').before('<div id="profiles" style="margin-bottom: 6px;"><span>Profiles: </span></div>');
for(i=0; i<=10; i++) $('#profiles').append('<a onclick="setProfile(' + i + '); return false;" href="#" style="padding: 1px 5px; margin: 0px 1px; background-color: #222; color: #EEE; border-radius: 3px;">' + (i ? i : 'Default') + '</a>');
$('#stats').css('height', '375px');
$('#stats hr').remove();
$('#socialStats').css('bottom', '65px');
$('#statsContinue').css('bottom', '25px');
$('#statsGraph').css('bottom', '120px').attr('height', '200px');
$('#s300x250').css('z-index', '-10');
addInfoPanel();
appendGoogleAd();
setInterval(appendGoogleAd, 120000);
$('footer').parent().append('<footer class="tosBox update"><a href="https://greasyfork.org/scripts/20003-agar-io-auto-respawn-code/code/Agario%20auto%20respawn%20code.js" target="_blank" class="text-muted" title="Last update: ' + timeSince(lastEdit) + ' ago">Source Code</a></footer>');
$('footer').parent().append('<footer class="tosBox donate"><form id="donate-mod" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank"><input name="cmd" value="_donations" type="hidden"><input name="business" value="[email protected]" type="hidden"><input name="lc" value="US" type="hidden"><input name="item_name" value="Donation" type="hidden"><input name="no_note" value="0" type="hidden"><input name="currency_code" value="USD" type="hidden"><input name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHostedGuest" type="hidden"><input name="submit" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" alt="PayPal - The safer, easier way to pay online!" border="0" type="image"><img src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" alt="" height="1" border="0" width="1"></form></footer>');
$('footer.tosBox.left').removeClass('left').addClass('gamemode').css({'bottom': '30px', 'right': '0px', 'font-size': '12px', 'background-color': '#3071A9', 'border-radius': '15px 0px 0px 15px', 'padding-left': '18px'});
$('footer.tosBox.right').removeClass('right').addClass('tos').css({'bottom': '0px', 'right': '0px', 'font-size': '12px', 'background-color': '#3071A9', 'border-radius': '15px 0px 0px 15px', 'padding-left': '18px'});
$('footer.tosBox.update').css({'bottom': '0px', 'right': '280px', 'font-size': '12px', 'background-color': '#398439', 'border-radius': '5px 5px 0px 0px'});
$('footer.tosBox.donate').css({'bottom': '-2px', 'right': '380px', 'font-size': '12px', 'background-color': 'transparent', 'padding': '0px'});
$('footer.tosBox a').css('color', '#FFFFFF');
}
function addInfoPanel() {
var editedDate = new Date(lastEdit);
$('footer').eq(0).before('<div id="infoPanel"><div id="infoPanel-header"><button onclick="toggleScriptInfo(); return false;">X</button><h2>Script Info</h2><span title="' + editedDate.toString() + '">Last update: ' + timeSince(lastEdit) + ' ago</span></div><div id="infoPanel-content"></div><div id="infoPanel-footer"></div></div>');
$('#infoPanel').css({'display': 'none', 'width': '820px', 'height': '500px', 'padding': '0px 20px', 'position': 'absolute', 'top': '50%', 'left': '50%', 'transform': 'translate(-50%, -50%)', 'background-color': '#123', 'color': '#AAA', 'border': '1px solid #000000', 'border-radius': '12px', 'box-shadow': '0px 0px 100px #012 inset'});
$('#infoPanel-header').css({'font-family': 'Consolas', 'color': '#EEE', 'padding': '20px 0px', 'text-align': 'center', 'border-bottom': '2px solid #28B', 'position': 'relative'});
$('#infoPanel-header button').css({'float': 'right', 'color': '#AAA', 'border': 'none', 'background-color': 'rgba(0, 0, 0, 0.3)', 'position': 'absolute', 'top': '10', 'right': '0'});
$('#infoPanel-header h2').css({'margin': '0px'});
$('#infoPanel-header span').css({'font-size': '80%', 'color': '#999'});
$('#infoPanel-content').css({'font-family': 'Tahoma, sans-serif', 'width': '780px', 'height': '338px', 'overflow': 'auto', 'margin': '20px 0px'});
$('#infoPanel-footer').css({'font-size': '80%'});
$('#infoPanel-content').html('<div id="infoPanel-content-features"><span style="color: #EEE;">Features</span><ul><li>Auto-save game settings<ul><li>Settings are saved automatically every time you makeachange.</li><li>Default name is ௌௌௌௌௌௌௌௌௌௌௌௌௌௌௌ</li></ul></li><li>Auto respawn - Enabling this will also make the Score counter to show real-time mass.</li><li>Spectator Mode - Enabling this will put you into spectator mode when you join a server.</li><li>Randomize Movement - Enabling this will make your cells change direction randomly every 5 seconds. Useful when going AFK.</li><li>Acid Mode</li><li>Refresh server button</li><li>Confirm dialog on tab close</li><li>Confirm dialog on logout</li><li>Hide ads and promos</li><li>Various ingame keyboard shortcuts</li></ul></div>\
<div id="infoPanel-content-changelogs"><span style="color: #EEE;">Changelog</span> <a href="#" onclick="toggleScriptInfoChangelog(); return false;" style="font-size: 11px;">Show</a><div style="display: none; width: 90%; background: rgba(0,0,0,0.3); font-size: 11px; padding: 10px"><ul style="padding-left: 20px;">\
<li>2016-05-27<ul><li>Changed source code location</li><li>Added auto-click hourly coin feature</li><li>Auto movement and autoclick coin interval now can be set</li></ul></li><li>2016-05-24 - Fixed broken stop moving and random moving function. The \'go to map center\' function is still broken though.</li><li>2016-05-23<ul><li>Opening free coins panel will automatically clicks the get coins button<li>Replaced promo banner with google ads banner</ul></li><li>2016-04-20 - Added profiles - you can save 10 different profiles each with their own settings</li><li>2016-04-06 - Changed leaderboard text to show what mode it currently is</li><li>2016-03-23<ul><li>Added confirm box on clicking log out button<li>Refresh server button now also works in party mode</li></li></ul></li><li>2016-03-01<ul><li>Made all panels opened with the ingame shortcut to be semi-transparent</li><li>Added new feature - Press , to open free coin panel</li><li>Added new feature - Spectator Mode - You will be put into spectatormode when you join a server</li></ul></li>\
<li>2015-02-19<ul><li>Added new feature - Press V to open skin panel</li><li>Added new feature - Press B to open shop panel</li><li>Added new feature - Press M to open mass boost panel</li><li>Added new feature - Press N to open xp panel</li><li>Removed checkboxes for ingame shortcut features - they are now not toggle-able</li><li>Reworked instruction UI</li></ul></li><li>2015-12-29<ul><li>Added new feature - Press R to eject mass 7 times</li><li>Added new fature - Press T to split 4 times</li></ul></li><li>2015-12-26<ul><li>Moved connecting panel to top right corner of the screen</li><li>Added region and gamemode info on connecting panel</li></ul></li><li>2015-12-24 - Added new feature - Acid mode</li><li>2015-12-23 - Resized stats panel to exclude ads height</li>\
<li>2015-12-22<ul><li>Added new feature - Press S key to stop movement</li><li>Added new feature - Press C to go to the center of the map</li><li>Added new feature - Randomize movement - change direction every 5 seconds</li></ul></li><li>2015-12-18 - Added changelog into the info panel</li><li>2015-12-16 - Added info panel</li><li>2015-12-13 - Fixed gamemode not always changing to the saved value</li><li>2015-12-11 - Fixed not being able to spectate</li><li>2015-12-09 - Script is now hosted on pastebin to make updating easy</li><li>2015-12-08<ul><li>Fixed overlay not displayed on center y-axis</li><li>Updated link for update script url</li><li>Added donate button in the footer</li></ul></li>\
<li>2015-12-06<ul><li>Added promo hiding</li><li>Stylized footer and moved it to the right</li></ul></li><li>2015-12-05<ul><li>Rewrote code to use jQuery</li><li>Fixed auto spawn not working for guest players</li><li>Added ads hiding feature</li><li>Added instruction for "hold E to W"</li><li>Added link to this page</li><li>Stylized instructions a little bit</li></ul></li><li>2015-12-02 - Added refresh server button</li><li>2015-12-01<ul><li>Fixed button style on chrome</li><li>Added "hold E to W" function</li><li>Removed debugging alert message</li></ul></li><li>2015-11-30 - Fixed auto spawn checkbox not working</li><li>2015-11-29 - Initial release</li></ul></div></div>');
$('#infoPanel-footer').html('<a href="https://greasyfork.org/en/scripts/14297-agar-io-auto-respawn-evergreen" target="_blank">Homepage</a> - <a href="https://greasyfork.org/scripts/20003-agar-io-auto-respawn-code/code/Agario%20auto%20respawn%20code.js" target="_blank">Source Code</a> - <a href="#" onclick="$(\'#donate-mod input[name=submit]\').click(); return false;">Donate</a>');
};
function startGame() { if(overlayClosed) MC.setNick($('#nick').val()); }
function randomMove() {
var mEv = new MouseEvent( 'mousemove', { 'clientX': getRandomInt(0, innerWidth), 'clientY': getRandomInt(0, innerHeight) });
canvas.dispatchEvent(mEv);
}
function sendEject() {
window.onkeydown({keyCode: 87});
window.onkeyup({keyCode: 87});
}
function sendMitosis() {
window.onkeydown({keyCode: 32});
window.onkeyup({keyCode: 32});
}
function appendGoogleAd() {
window.google_ad_client = "ca-pub-8318511014856551"; window.google_ad_slot = "5881481221"; window.google_ad_width = 300; window.google_ad_height = 250;
var container = document.getElementById('agario-web-incentive');
container.style.backgroundImage = '';
var w = document.write;
document.write = function (content) {
container.innerHTML = content;
document.write = w;
};
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://pagead2.googlesyndication.com/pagead/show_ads.js';
document.body.appendChild(script);
}
function hookOverlay() {
$('button[data-itr="play"]').click(function() { overlayClosed = true; });
$('button[data-itr="play_as_guest"]').click(function() { overlayClosed = true; });
$('button[data-itr="spectate"]').click(function() { overlayClosed = false; });
$('button[data-itr="logout"]').click(function() { var lg = confirm('Logout?'); if(lg) logout(); });
$.each(['show', 'hide'], function (i, ev) { var el = $.fn[ev]; $.fn[ev] = function () { this.trigger(ev); return el.apply(this, arguments); }; });
$('#connecting').on('show', function() { connectingInfo(); });
$('#connecting').on('hide', function() { if(spectatorMode) $('button[data-itr="spectate"]').click(); leaderboardText(); });
$('#openfl-content').on('hide', function() { setTimeout(function() { $('#openfl-content').css({'opacity' : '1'}); }, 10); });
}
function applyConfig() {
var checkbox = $('#options input[type="checkbox"]');
checkbox.prop('checked', false);
checkbox.change(function() {
profileSettings[$(this).next().attr('data-itr')] = $(this).prop('checked');
localStorage.setItem('profile' + localStorage.getItem('activeprofile'), JSON.stringify(profileSettings));
});
$('#nick, #gamemode, #region, #quality, #randommove_interval, #clickcoin_interval').change(function() {
profileSettings[$(this).attr('id')] = $(this).val();
localStorage.setItem('profile' + localStorage.getItem('activeprofile'), JSON.stringify(profileSettings));
});
setProfile(localStorage.getItem('activeprofile'));
}
function showPanels(panel) {
$('#openfl-content').css({'opacity' : '0.35'});
if(panel == 1) $('#openShopBtn').click();
else if(panel == 2) $('#skinButton').click();
else if(panel == 3) $('#boostButton').click();
else if(panel == 4) $('#massButton').click();
else if(panel == 5) $('#freeCoins').click();
}
$('#freeCoins').on('click', function() { setTimeout(clickHourlyCoin, 1000); });
function connectingInfo() { $('#connectingToInfo').text($('#region option:selected').text().split(' (')[0] + ' - ' + $('#gamemode option:selected').text()) }
function leaderboardText() {
var curMode = $('#gamemode option:selected').text();
if(curMode.length > 8) curMode = curMode.slice(0, 7) + '...';
i18n.leaderboard = '≡ ' + curMode;
console.log(i18n.leaderboard);
}
function timeSince(date) {
var seconds = Math.floor((new Date() - date) / 1000);
var interval = Math.floor(seconds / 31536000);
if(interval > 1) return interval + ' years'; interval = Math.floor(seconds / 2592000);
if(interval > 1) return interval + ' months'; interval = Math.floor(seconds / 86400);
if(interval > 1) return interval + ' days'; interval = Math.floor(seconds / 3600);
if(interval > 1) return interval + ' hours'; interval = Math.floor(seconds / 60);
if(interval > 1) return interval + ' minutes';
return Math.floor(seconds) + ' seconds';
}
function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }
function setIntervalX(callback, delay, repetitions) {
var x = 0;
var intervalID = window.setInterval(function () {
callback();
if (++x === repetitions) window.clearInterval(intervalID);
}, delay);
}
function clickHourlyCoin() {
var posX = window.innerWidth / 2 - 150;
var posY = window.innerHeight / 2 + 30;
simulateClick(posX, posY)
setTimeout(function() {
posX = window.innerWidth / 2 + 192;
posY = window.innerHeight / 2 - 208;
simulateClick(posX, posY)
}, 3500);
setTimeout(function() {
posX = window.innerWidth / 2 + 192;
posY = window.innerHeight / 2 - 160;
simulateClick(posX, posY)
}, 3600);
setTimeout(function() {
posX = window.innerWidth / 2 + 192;
posY = window.innerHeight / 2 - 150;
simulateClick(posX, posY)
}, 3700);
setTimeout(function() {
posX = window.innerWidth / 2 + 234;
posY = window.innerHeight / 2 - 62;
simulateClick(posX, posY)
}, 5000);
}
function simulateClick(x,y) {
var el, ev;
el = document.elementFromPoint(x,y);
ev = new MouseEvent('mousedown', { 'clientX': x, 'clientY': y }); el.dispatchEvent(ev);
ev = new MouseEvent('mouseup', { 'clientX': x, 'clientY': y }); el.dispatchEvent(ev);
}
/*
var script = document.createElement('script');
script.src = document.location.protocol+"//greasyfork.org/scripts/20003-agar-io-auto-respawn-code/code/Agario%20auto%20respawn%20code.js";
(document.body || document.head || document.documentElement).appendChild(script);
*/