Agar.io Extras

Adds functionality and improves aesthetic.

目前為 2017-07-10 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 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 Extras
// @description  Adds functionality and improves aesthetic.
// @include      http://agar.io/*
// @grant        none
// @run-at       document-start
// @version      1.2
// @author       Jack Burch + Tom Burris
// @namespace    https://greasyfork.org/en/users/46159
// @license      GPLv3, https://en.wikipedia.org/wiki/GNU_General_Public_License, https://www.gnu.org/licenses/quick-guide-gplv3.html
// @icon         http://bit.ly/2oT4wRk
// @compatible   chrome
// @compatible   firefox
// @compatible   safari
// @compatible   opera
// ==/UserScript==

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

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

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

	class Stylesheet {
		constructor(id) {
			this.id = id;
			this.text = '';
		}
		addRules() {
			for (let n = 0; n < arguments.length; n += 2) {
				this.text += arguments[n] + ' {\n';
				var props = Object.keys(arguments[n + 1]);
				for (let prop of props) {
					this.text += '\t' + prop + ': ' + arguments[n + 1][prop] + ';\n';
				}
				this.text += '}\n';
			}
		}
		addToPage() {
			var style = document.createElement('style');
			style.id = this.id;
			style.textContent = this.text;
			document.head.appendChild(style);
		}
	}
	var css = new Stylesheet("AgarExtrasStyle");

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

	/* Compact Left Panel */
	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.addRules('.quest-timer', {
		'width': 'auto',
		'margin-left': '20px',
	},'.btn-gifting, #dailyQuests', {
		'margin-bottom': '10px',
	},'#dailyquests-panel, .agario-shop-panel, #giftButton', {
		'display': 'none !important',
	});

	/* Center Options */
	var spans = document.getElementById('options').getElementsByTagName('span');
	for(let span of spans) {
		if(span.textContent == 'Show Online Status') {
			span.textContent = 'Show Online';
		}
	}
	css.addRules('#tags-container', {
		'display': 'none',
	},'#options', {
		'margin-left': '25px',
	});

	/* 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);
	var fillTextOld = CanvasRenderingContext2D.prototype.fillText;
	var topTen = [];
	CanvasRenderingContext2D.prototype.fillText = 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.addRules('#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.id = 'fpsBox';
	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');
	var clearRectOld = ctx.clearRect;
	ctx.clearRect = function() {
		frames++;
		return clearRectOld.apply(this, arguments);
	};
	css.addRules('#fpsBox', {
		'position': 'absolute',
		'left': '0px',
		'top': '0px',
		'color': 'white',
		'background': 'black',
	});

	/* Drawing? */
	var requestAnimationFrameOld = window.requestAnimationFrame;
	window.requestAnimationFrame = 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.addRules('#wsTextInput', {
		'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 < 3; n++) {
					setTimeout(window.core.split, n * speed);
				}
				break;
			case 3: // Right click
				ejectDown = true;
				eject();
		}
	});
	function eject() {
		if (ejectDown) {
			window.core.eject();
			setTimeout(eject, speed);
		}
	}
	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();
	}

	/* 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': function() {
					player.setVolume(50);
					player.setPlaybackQuality('small');
				}
			}
		});
	};
	css.addRules('#musicPlayer', {
		'padding': '0px',
		'width': '293px',
		'height': '165px',
		'margin-top': '5px',
	});

	/* Ubuntu Font */
	var ubuntuLink = document.createElement("link");
	ubuntuLink.href = 'https://fonts.googleapis.com/css?family=Ubuntu';
	document.head.appendChild(ubuntuLink);
	css.addRules('body', {
		'font-family': "'Ubuntu', sans-serif !important",
	},'#statsSubtext', {
		'white-space': 'nowrap',
	});

	/* Vertically center main panel */
	css.addRules('#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 Instructions */
	css.addRules('#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',
	});

	/* Move Login Button */
	document.getElementsByClassName('btn-spectate')[0].parentNode.appendChild(document.getElementsByClassName('btn-login-play')[0]);

	/* Darken Stuff */
	css.addRules('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.addRules('.agario-promo-container, #advertisement, .diep-cross, #promo-badge-container, #agario-web-incentive, #mcbanners-container, #adsBottom', {
		'display': 'none !important',
	});

	css.addToPage();
});

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

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