// ==UserScript==
// @name Agar.io Plus
// @description Improves the functionality and style of agar.io
// @match http://agar.io/*
// @grant none
// @version 0.3
// @author Jack Burch + Tom Burris
// @namespace https://greasyfork.org/en/users/46159
// @icon http://bit.ly/2oT4wRk
// @compatible chrome
// @compatible firefox
// @compatible safari
// @compatible opera
// @noframes
// ==/UserScript==
(function() {
'use strict';
var css = "";
/* Compact Left Panel */
css += ".quest-timer {width: auto; margin-left: 20px;}";
var profilePanel = document.getElementsByClassName("agario-profile-panel")[0];
profilePanel.appendChild(document.getElementById("dailyQuests"));
document.getElementById("dailyQuests").appendChild(document.getElementsByClassName("quest-timer")[0]);
var shopStuff = document.getElementsByClassName("agario-shop-panel")[0].childNodes;
while(shopStuff.length) {
profilePanel.appendChild(shopStuff[0]);
}
css += ".btn-gifting, #dailyQuests {margin-bottom: 10px;}";
css += "#dailyquests-panel, .agario-shop-panel, #giftButton {display: none !important;}";
/* Center Options */
css += "#tags-container {display: none;} #options {margin-left: 25px;}";
var spans = document.getElementById("options").getElementsByTagName("span");
for(var span of spans) {
if(span.textContent == "Show Online Status") {
span.textContent = "Show Online";
}
}
/* 'f' Key Toggles Fullscreen */
function skipBrowserInconsistencies(object, properties) {
for (var property of properties) {
if (object[property] !== undefined) {
return object[property];
}
}
throw new Error("Browser does not have any: " + properties.join(", "));
}
var fullscreen = skipBrowserInconsistencies(document.body,
["requestFullscreen", "webkitRequestFullscreen", "mozRequestFullScreen"]
).bind(document.body);
var exitFullscreen = skipBrowserInconsistencies(document,
["exitFullscreen", "webkitExitFullscreen", "mozCancelFullScreen"]
).bind(document);
var isFullscreen = function() {
return skipBrowserInconsistencies(document,
["fullscreen", "webkitIsFullScreen", "mozFullScreen"]);
};
window.addEventListener("keydown", function(event) {
if (event.keyCode == 70) {
if (isFullscreen()) {
exitFullscreen();
} else {
fullscreen();
}
}
});
/* Mouse Controls */
var speed = 50;
var ejectDown = false;
var canvas = document.getElementById("canvas");
canvas.addEventListener("mousedown", function(event) {
switch(event.which) {
case 1:
window.core.split();
break;
case 2:
for(var n = 0; n < 4; n++) {
setTimeout(window.core.split, n * speed);
}
break;
case 3:
ejectDown = true;
eject();
break;
}
});
window.addEventListener("mouseup", function(event) {
if (event.which == 3) {
ejectDown = false;
}
});
canvas.addEventListener("mousewheel", function(event) {
canvas.dispatchEvent(new MouseEvent('mousemove', {'clientX': window.innerWidth/2, 'clientY': window.innerHeight/2}));
});
canvas.addEventListener("contextmenu", prevent);
canvas.addEventListener("drag", prevent);
function eject() {
if (ejectDown) {
window.core.eject();
setTimeout(eject, speed);
}
}
function prevent(event) {
event.preventDefault();
}
/* Arrow Keys */
var keys = [37, 38, 39, 40];
var keysDown = {};
var directions = [-1, -1, 1, 1];
document.addEventListener("keydown", keychange);
document.addEventListener("keyup", keychange);
function keychange() {
if (keys.includes(event.keyCode)) {
keysDown[event.keyCode] = event.type == "keydown";
update();
}
}
function update() {
var moveEvent = new Event("mousemove");
moveEvent.clientX = window.innerWidth / 2;
moveEvent.clientY = window.innerHeight / 2;
for (var n = 0; n < keys.length; n++) {
if (keysDown[keys[n]]) {
moveEvent["client" + ((n % 2 === 0) ? "X" : "Y")] += directions[n] * Math.min(window.innerWidth, window.innerHeight);
}
}
document.getElementById("canvas").dispatchEvent(moveEvent);
}
/* Add Music Player */
var src = "http://www.youtube.com/embed/1-AODuJpCG4" + "?controls=0;";
var player = document.createElement("div");
player.className = "agario-panel agario-side-panel";
player.style = "padding: 0px; width: 293px; height: 168px; margin-top: 5px;";
player.innerHTML = '<iframe id="YTVideo" src="' +
src + '" style="border: 0px; width: 100%; height: 100%;"></iframe>';
document.getElementById("rightPanel").appendChild(player);
/* Add Acid Mode */
var label = document.createElement("label");
label.innerHTML = '<input type="checkbox" id="acidMode" style="margin-top: 1px"><span>Acid mode</span>';
document.getElementById("options").appendChild(label);
var checkbox = document.getElementById("acidMode");
checkbox.addEventListener("click", function() {
core.setAcid(checkbox.checked);
});
/* Remove Video Ads */
setTimeout(function() {
initAdsController = function() {};
requestAds = function() {
MC.notifyFullscreenAdFinished();
};
onAdLoaded = function() {
onDone();
};
}, 5000);
/* Ubuntu Font */
css += "@import url('https://fonts.googleapis.com/css?family=Ubuntu');";
document.body.style.setProperty("font-family", "'Ubuntu', sans-serif", "important");
/* Vertically center main panel */
css += `
#helloContainer {
position: relative;
top: 50% !important;
transform: perspective(1px) translate(-50%, -50%) !important;
display: inline-block !important;
width: auto !important;
}
#leftPanel {
margin: 0px;
width: 222px;
}
`;
/* Always display settings and intructions, also move the login button */
css += `
#settings {
display: block !important;
}
.btn-settings {
display: none;
}
.btn-play-guest {
width: 100%;
margin: 0px !important;
}
.btn-play {
width: 100% !important;
margin: 0px !important;
}
.btn-login-play {
width: 110px !important;
float: right;
}
#instructions,
#options,
.text-muted,
#mainPanel {
cursor: default !important;
}
input,
select {
cursor: pointer !important;
}
`;
document.getElementsByClassName("btn-spectate")[0].parentNode.
appendChild(document.getElementsByClassName("btn-login-play")[0]).
textContent = "Login";
/* Blurry Font Fix */
css += "body {line-height: normal !important;}";
/* Darken Stuff */
css += `
select,
.agario-panel,
.shop-blocker,
#blocker,
#nick,
footer,
.progress,
.party-token,
.agario-profile-picture {
background: black !important;
color: white !important;
border: 0px !important;
border-radius: 0px !important;
outline: 1px solid white !important;
}
span {
color: white !important;
}
.party-icon-back {
background: black !important;
}
.btn {
border-radius: 0px;
}
`;
/* Hide Static Ads */
css += `
.agario-promo-container,
#advertisement,
.diep-cross,
#promo-badge-container,
#agario-web-incentive,
#mcbanners-container {
display: none !important;
}
`;
/* Append CSS To DOM */
var style = document.createElement("style");
style.innerHTML = css;
document.head.appendChild(style);
})();