Wings.io auto respawn (evergreen)

Auto respawn, auto fire, remember name and settings, warn on tab close and more

当前为 2016-07-05 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Wings.io auto respawn (evergreen)
// @namespace   wingsiomodrawr
// @description Auto respawn, auto fire, remember name and settings, warn on tab close and more
// @version     4
// @author      condoriano
// @icon        http://i.imgur.com/pECyZov.png
// @include     http://wings.io/*
// @include     https://wings.io/*
// @run-at      document-start
// @grant       none
// ==/UserScript==

if(window.self != window.top) return;

if(navigator.userAgent.toLowerCase().indexOf('firefox') != -1) {
	var scriptChanged = false;
	window.addEventListener('beforescriptexecute', function(e) {
		if(e.target.innerHTML.length > 120000 && !scriptChanged) {
			e.preventDefault();
			e.stopPropagation();
			scriptChanged = true;
			e.target.remove();
			var oriScript = e.target.innerHTML;
			var httpReq = new XMLHttpRequest();
			httpReq.open('GET', 'http://greasyfork.org/scripts/20020-wingsiomod/code/wingsiomod.js', true);
			httpReq.onreadystatechange = function() {
				if(httpReq.readyState == 4 && httpReq.status == 200) {
					var modScript = httpReq.responseText.trim().replace(/^function.*{|}$/g, '');
					var finalScript = combineScript(oriScript, modScript);
					var elem = document.createElement('script');
					elem.innerHTML = finalScript;
					document.body.appendChild(elem);
				}
			};
			httpReq.send();
		}
		if(scriptChanged) window.removeEventListener(e.type, arguments.callee, true);
	}, true);
}
else {
	window.stop();
	var httpReq = new XMLHttpRequest();
	httpReq.open('GET', 'http://wings.io/', true);
	httpReq.onreadystatechange = function() {
		if(httpReq.readyState == 4 && httpReq.status == 200) {
			var tempDOM = document.createElement('div');
			tempDOM.innerHTML = httpReq.responseText;
			for(var i = 0; i < tempDOM.children.length; i++) {
				if(tempDOM.children[i].tagName.toUpperCase() == 'SCRIPT' && tempDOM.children[i].innerHTML.length > 120000) {
					var oriScript = tempDOM.children[i].innerHTML;
					var httpReq2 = new XMLHttpRequest();
					httpReq2.open('GET', 'http://greasyfork.org/scripts/20020-wingsiomod/code/wingsiomod.js', true);
					httpReq2.onreadystatechange = function() {
						if(httpReq2.readyState == 4 && httpReq2.status == 200) {
							var modScript = httpReq2.responseText.trim().replace(/^function.*{|}$/g, '');
							var finalScript = combineScript(oriScript, modScript);

							tempDOM.children[i].innerHTML = finalScript;
							document.open();
							document.write(tempDOM.innerHTML);
							document.close();

						};
					}
					httpReq2.send();
					break;
				}
			}
		};
	}
	httpReq.send();
}

function combineScript(a, b) {
	a = a.replace('"#62bae2"', 'handleColors("#62bae2")'); // solid bg when disabled gradient enabled
	a = a.replace(/("rgba\("\+parseInt\(f\)\+",145,202,1\.0\)")/, 'handleColors($1)'); // sky
	a = a.replace(/("rgba\("\+parseInt\(m\)\+",231,252,1\.0\)")/, 'handleColors($1)'); // sky
	a = a.replace(/("rgba\(9,188,255,1\.0\)")/g, 'handleColors($1)'); // water
	a = a.replace(/("rgba\(8,164,254,1\.0\)")/g, 'handleColors($1)'); // water
	a = a.replace(/("rgba\(7,142,252,1\.0\)")/g, 'handleColors($1)'); // water
	a = a.replace(/("rgba\(0,132,232,1\.0\)")/g, 'handleColors($1)'); // water
	a = a.replace(/("rgba\(0,90,190,1\.0\)")/g, 'handleColors($1)'); // water
	a = a.replace(/\(function\((.....)\){/i, '(function($1){' + b);
	return a;
}