Agar.io Plus

Improves the functionality and style of agar.io

目前為 2017-06-25 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Agar.io Plus
// @description  Improves the functionality and style of agar.io
// @include      *agar.io/*
// @grant        none
// @run-at       document-start
// @version      0.9
// @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';

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

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

	/* 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);
	CanvasRenderingContext2D.prototype.clearRect = (function() {
		var clearRectOld = CanvasRenderingContext2D.prototype.clearRect;
		return function() {
			if (this.canvas.id == "canvas") {
				frames++;
			}
			return clearRectOld.apply(this, arguments);
		};
	})();

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

	/* Capture Cells? */
	var ctx = window.canvas.getContext("2d");
	ctx.arc = (function() {
		var arcOld = ctx.arc.bind(ctx);
		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("anything", 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) {
			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.keyCode == 70 && event.target.tagName.toLowerCase() != "input") {
		    if (isFullscreen()) {
				exitFullscreen();
			} else {
				fullscreen();
			}
		}
	});

	/* Mouse Controls */
	var speed = 50;
    var ejectDown = false;
    window.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;
        }
    });
    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];
    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);
            }
        }
        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: 'j-Oc38mSZL4',
			events: {
				'onReady': onPlayerReady,
			}
		});
	};
	window.onPlayerReady = function() {
		player.setVolume(50);
	};
	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 {
            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;
        }
    `;

	/* 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();
	};
	//window.startAd = function() {}; // banner.js line 1
	//console.log("%cDone!", "color:black;font-weight:bold;font-size:20px;");
});