Agar.io Extras

Adds functionality and improves aesthetic.

当前为 2017-07-09 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Agar.io Extras
// @description  Adds functionality and improves aesthetic.
// @include      http://agar.io/*
// @grant        none
// @run-at       document-start
// @version      1.1
// @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
// ==/UserScript==

/* document-start */
(function() {
	'use strict';

	/* Overwrite WebSocket Contructor */
	window.WebSocket = (function() {
		var WebSocketOld = window.WebSocket;
		return function() {
			return new WebSocketOld(window.wsURL = document.getElementById("wsTextInput").value = arguments[0].replace(/\?.*$/, ""), arguments[1]);
		};
	})();
})();

/* document-end */
document.addEventListener("DOMContentLoaded", function() {
    'use strict';

	var css = "";

	/* Fixes */
    css += "body {line-height: normal !important;}"; // blurry font.
	document.getElementById("nick").type = "text"; // improper input.

	/* 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";
		}
	}

	/* 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);
    });

	/* Leaderboard Names */
	var nameBox = document.createElement("div");
	nameBox.id = "nameBox";
	nameBox.className = "agario-panel";
	for (let n = 0; n < 11; n++) {
		nameBox.appendChild(document.createElement("div"));
	}
	nameBox.children[10].textContent = "L = Toggle";
	nameBox.children[10].style.color = "#999";
	document.getElementById("overlays").appendChild(nameBox);
	CanvasRenderingContext2D.prototype.fillText = (function() {
		var fillTextOld = CanvasRenderingContext2D.prototype.fillText;
		var topTen = [];
		return function() {
			if (topTen.length < 10) {
				topTen.push(arguments[0].substring(3));
				if (topTen.length == 10) {
					var nameSpots = nameBox.children;
					for (let n = 0; n < 10; n++) {
						nameSpots[n].textContent = topTen[n];
					}
				}
			} else if (arguments[0] == "Leaderboard") {
				topTen.length = 0;
			}
			return fillTextOld.apply(this, arguments);
		};
	})();
	css += `
		#nameBox {
			position: absolute;
			right: 0px;
			top: 0px;
			width: auto;
			padding: 10px;
			margin: 10px;
			display: inline-block;
		}
	`;
	window.addEventListener("keydown", function(event) {
		if (event.target.tagName.toLowerCase() != "input" && event.keyCode == 76) { // l
			nameBox.style.display = (nameBox.style.display == "none" ? "inline-block" : "none");
		}
	});

	/* FPS */
	var fpsBox = document.createElement("div");
	fpsBox.style = "position: absolute; top: 0px; left: 0px; color: white; background: black;";
	document.body.appendChild(fpsBox);
	var frames = 0;
	setInterval(function() {
		fpsBox.textContent = "fps: " + frames;
		fpsBox.style.color = "hsl(" + frames * 2 + ", 100%, 50%)";
		frames = 0;
	}, 1E3);
	var ctx = window.canvas.getContext("2d");
	ctx.clearRect = (function() {
		var clearRectOld = ctx.clearRect;
		return function() {
			frames++;
			return clearRectOld.apply(this, arguments);
		};
	})();

	/* Capture Cells? */
	ctx.arc = (function() {
		var arcOld = ctx.arc;
		return function() {
			//You can keep track of the cells here.
			//cells.push({x: arguments[0], y: arguments[1], r: arguments[2]});
			//keep in mind that there are two arcs for each cell though.
			return arcOld.apply(this, arguments);
		};
	})();

	/* Drawing? */
	window.requestAnimationFrame = (function() {
		var requestAnimationFrameOld = window.requestAnimationFrame;
		return function() {
			ctx.save();
			// You can draw stuff to the canvas here.
			ctx.restore();
			return requestAnimationFrameOld.apply(this, arguments);
		};
	})();

	/* Server Connection */
	var wsBox = document.createElement("div");
	wsBox.innerHTML = `
		<input type="text" id='wsTextInput' class='agario-panel agario-side-panel' spellcheck='false'></input>
	`;
	document.getElementById("rightPanel").appendChild(wsBox);
	var wsTextInput = document.getElementById("wsTextInput");
	wsTextInput.addEventListener("focus", function() {
		wsTextInput.select();
	});
	wsTextInput.addEventListener("blur", function() {
		wsTextInput.value = window.wsURL;
	});
	wsTextInput.addEventListener("keypress", function(event) {
		if (event.keyCode == 13) { // Enter
			core.disconnect();
			core.connect(wsTextInput.value);
			document.getElementsByClassName("btn-play")[0].click();
		}
	});
	css += `
		#wsTextInput {
			text-overflow: ellipsis;
			padding: 6px;
			display: inline-block;
			width: 293px;
			height: 34px;
		}
		#wsTextInput:focus {
			outline: 0px !important;
			box-shadow: 0 0 3px 1px white;
		}
		::selection {
			background: #0d0 !important;
		}
	`;

	/* '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(", or "));
	}
	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.target.tagName.toLowerCase() != "input" && event.keyCode == 70) { // f
		    if (isFullscreen()) {
				exitFullscreen();
			} else {
				fullscreen();
			}
		}
	});

	/* Mouse Controls */
	var speed = 50;
    var ejectDown = false;
    window.canvas.addEventListener("mousedown", function(event) {
        switch(event.which) {
            case 1: // Left click
                window.core.split();
                break;
            case 2: // Middle click
                for(var n = 0; n < 4; n++) {
                    setTimeout(window.core.split, n * speed);
                }
                break;
            case 3: // Right click
                ejectDown = true;
                eject();
                break;
        }
    });
    window.addEventListener("mouseup", function(event) {
        if (event.which == 3) { // Right mouse button
            ejectDown = false;
        }
    });
    window.canvas.addEventListener("mousewheel", function(event) {
        window.canvas.dispatchEvent(new MouseEvent('mousemove', {'clientX': window.innerWidth/2, 'clientY': window.innerHeight/2}));
    });
    window.canvas.addEventListener("contextmenu", prevent);
    window.canvas.addEventListener("dragstart", prevent);
	function prevent(event) {
        event.preventDefault();
    }
    function eject() {
        if (ejectDown) {
            window.core.eject();
            setTimeout(eject, speed);
        }
    }

	/* Arrow Keys */
	var keys = [37, 38, 39, 40]; // left, up, right, down arrows
    var keysDown = {};
    var directions = [-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/2)] * Math.min(window.innerWidth, window.innerHeight);
            }
        }
        window.canvas.dispatchEvent(moveEvent);
    }

	/* Music Player */
    var music = document.createElement("div");
	music.id = "musicPlayer";
	music.className = "agario-panel agario-side-panel";
	document.getElementById("rightPanel").appendChild(music);
	var ytScript = document.createElement('script');
    ytScript.src = "https://www.youtube.com/iframe_api";
    document.head.appendChild(ytScript);
	var player;
	window.onYouTubeIframeAPIReady = function() {
		player = new YT.Player('musicPlayer', {
			videoId: '7uXLkqT6Qqc',
			events: {
				'onReady': onPlayerReady,
			}
		});
	};
	window.onPlayerReady = function() {
		player.setVolume(50);
		player.setPlaybackQuality("small");
	};
	css += `
		#musicPlayer {
			padding: 0px;
			width: 293px;
			height: 165px;
			margin-top: 5px;
		}
	`;

	/* Ubuntu Font */
	css += "@import url('https://fonts.googleapis.com/css?family=Ubuntu');";
	document.body.style.setProperty("font-family", "'Ubuntu', sans-serif", "important");
	css += "#statsSubtext {white-space: nowrap;}";

    /* 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,
		#instructions {
            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]);

    /* Darken Stuff */
    css += `
        select,
        .agario-panel,
        .shop-blocker,
        #blocker,
        input[type=text],
        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 !important;
        }
		.close {
			color: white;
			opacity: 1;
		}
    `;

	/* Hide Static Ads */
	css += `
        .agario-promo-container,
        #advertisement,
        .diep-cross,
        #promo-badge-container,
        #agario-web-incentive,
        #mcbanners-container,
        #adsBottom {
            display: none !important;
        }
    `;

	/* Append CSS To DOM */
	var style = document.createElement("style");
	style.innerHTML = css;
	document.head.appendChild(style);
});

/* document-idle */
window.addEventListener("load", function() {
	// The page javascript changes the textContent (I think).
	document.getElementsByClassName("btn-login-play")[0].textContent = "Login";

	/* Remove Video Ads */
	window.initAdsController = function() {};
	window.requestAds = function() {
		MC.notifyFullscreenAdFinished();
	};
	window.onAdLoaded = function() {
		window.onDone();
	};
});