QT Framework for Grepolis

A script framework for Grepolis

当前为 2014-07-29 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name           QT Framework for Grepolis
// @namespace      Quack
// @description    A script framework for Grepolis
// @include        http://*.grepolis.*/game*
// @icon           http://s1.directupload.net/images/140711/eshmcqzu.png
// @version        1.02.00
// @grant          GM_listValues
// @grant          GM_getValue
// @grant          GM_setValue
// @grant          GM_deleteValue
// @grant          GM_info
// @grant          GM_xmlhttpRequest
// ==/UserScript==

/************************************************************************
 * Main Script
 ***********************************************************************/
function main_script(DATA) {
	/************************************************************************
	 * Global variables
	 ***********************************************************************/
	var QT = {};
	var wID = Game.world_id;
	var mID = Game.market_id;
	var aID = Game.alliance_id;
	var sID = Game.player_id;
	var pName = Game.player_name;

	/************************************************************************
	 * Languages
	 ***********************************************************************/
	QT.Lang = {
		get : function (a, b) {
			if (QT.Lang[mID] != undefined && QT.Lang[mID][a] != undefined && QT.Lang[mID][a][b] != undefined) {
				return QT.Lang[mID][a][b]
			} else {
				return QT.Lang.en[a][b]
			}
		},
		de : {
			meta : {
				flag : 'http://s14.directupload.net/images/140408/xpd69nmj.png',
				changelog : 'http://adf.ly/cph8j',
				changelog_addfree : 'https://docs.google.com/document/d/10AyoYbgB1ml30EhSyXF7lDgEw_VqgHIQoJrJPCT0Z3w/edit?usp=sharing',
				forumlink : 'http://adf.ly/cbQaZ',
				forumlink_addfree : 'http://forum.de.grepolis.com/showthread.php?20742',
				donation_btn : '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=2HJ88ATTBYXSQ&lc=DE&item_name=Quack%20Toolsammlung&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted" target="_blank"><img src="https://www.paypal.com/de_DE/i/btn/btn_donate_LG.gif" alt="Spenden"></a>'
			},
			test : {
				teststring : 'Sprache wurde erkannt'
			}
		},
		en : {
			meta : {
				flag : 'http://s14.directupload.net/images/140408/e2nfyth9.png',
				changelog : 'http://adf.ly/cpi89',
				changelog_addfree : 'https://docs.google.com/document/d/1Q9wIHhXUu6cDUdxr0onT8sHOcSXxpAtbg6R_oOrhiA8/edit?usp=sharing',
				forumlink : 'http://adf.ly/fJDMD',
				forumlink_addfree : 'http://forum.en.grepolis.com/showthread.php?51999',
				donation_btn : '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=2HJ88ATTBYXSQ&lc=US&item_name=Quack%20Toolsammlung&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted" target="_blank"><img src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" alt="Donate"></a>'
			},
			test : {
				teststring : 'Language detected'
			}
		}
	};

	/************************************************************************
	 * Images
	 ***********************************************************************/
	QT.Images = {};

	/************************************************************************
	 * Links
	 ***********************************************************************/
	QT.Links = {};

	/************************************************************************
	 * Settings
	 ***********************************************************************/
	QT.Settings = {
		values : {
			"messageOpenAlert" : true,
			"reportOpenAlert" : true,
			"onlinetotal" : 0
		},
		save : function (name, value) {
			QT_saveValue(name, value);
		},
		save_all : function (valuesToSave) {
			QT_saveAllValues(QT.Settings.values, valuesToSave);
		},
		delete : function (name) {
			QT_deleteValue(name);
		},
		delete_all : function () {
			QT_deleteAllValues();
		},
		setValues : function () {
			for (var opt in DATA) {
				QT.Settings.values[opt] = DATA[opt];
			}
		}
	};

	/************************************************************************
	 * Ajax Call functions
	 ***********************************************************************/
	QT.CallAjaxFunction = {
		message : {
		default:
			function (event, xhr, settings) {
				if (QT.Settings.values.messageOpenAlert)
					QT.Functions.messageOpenAlert();
			}
		},
		report : {
			index : function () {
				if (QT.Settings.values.reportOpenAlert)
					QT.Functions.reportOpenAlert();
			}
		}
	};

	/************************************************************************
	 * Functions
	 ***********************************************************************/
	QT.Functions = {
		messageOpenAlert : function () {
			alert("Die Nachrichten wurden geöffnet");
		},
		reportOpenAlert : function () {
			alert("Die Berichte wurden geöffnet");
		},
		testButtons : function () {
			$('#ui_box').append('<div id="qt_buttons" style="position: relative;top: 54px;z-index: 100"><button id="qt_save">Save</button><button id="qt_saveall">Save all</button><button id="qt_delete">Delete</button><button id="qt_deleteall">Delete all</button></div>');
			$("#qt_save").click(function () {
				QT.Settings.save("messageOpenAlert", false);
			});
			$("#qt_saveall").click(function () {
				var values = {};
				values.messageOpenAlert = false;
				values.reportOpenAlert = false;
				QT.Settings.save_all(values);
			});
			$("#qt_delete").click(function () {
				QT.Settings.delete("messageOpenAlert");
			});
			$("#qt_deleteall").click(function () {
				QT.Settings.delete_all();
			});
		}
	};

	/************************************************************************
	 * Observer
	 ***********************************************************************/
	$.Observer(GameEvents.game.load).subscribe('QT', function (e, data) {
		QT.Settings.setValues();
		QT.Functions.testButtons();

		$(document).ajaxComplete(function (event, xhr, settings) {
			var a = settings.url.split("?");
			var b = a[0].substr(6);
			var c = a[1].split("&")[1].substr(7);
			if (b in QT.CallAjaxFunction && c in QT.CallAjaxFunction[b]) {
				QT.CallAjaxFunction[b][c](event, xhr, settings);
			}
		});
	});
}

/************************************************************************
 * Start Method
 ***********************************************************************/
var DATA = {
	script_version : GM_info.script.version
};

var keys = GM_listValues();
for (var i = 0, key = null; key = keys[i]; i++) {
	DATA[key] = GM_getValue(key);
}

unsafeWindow.QT_saveValue = function (name, val) {
	setTimeout(function () {
		GM_setValue(name, val);
		window.location.reload();
	}, 0);
};
unsafeWindow.QT_saveAllValues = function (QTsettings, values) {
	setTimeout(function () {
		var exceptions = ["qmenu_update_next", "qmenu_online_version", "onlinetotal"];
		for (key in QTsettings) {
			if (exceptions.indexOf(key) === -1) {
				if (key in values) {
					GM_setValue(key, values[key]);
				} else {
					GM_deleteValue(key);
				}
			}
		}
		window.location.reload();
	}, 0);
};
unsafeWindow.QT_deleteValue = function (name) {
	setTimeout(function () {
		GM_deleteValue(name);
		window.location.reload();
	}, 0);
};
unsafeWindow.QT_deleteAllValues = function () {
	setTimeout(function () {
		var keys = GM_listValues();
		for (var i = 0, key = null; key = keys[i]; i++) {
			GM_deleteValue(key);
		}
		window.location.reload();
	}, 0);
};

if (typeof exportFunction == 'function') {
	exportFunction(unsafeWindow.QT_saveValue, unsafeWindow, {
		defineAs : "QT_saveValue"
	});
	exportFunction(unsafeWindow.QT_saveAllValues, unsafeWindow, {
		defineAs : "QT_saveAllValues"
	});
	exportFunction(unsafeWindow.QT_deleteValue, unsafeWindow, {
		defineAs : "QT_deleteValue"
	});
	exportFunction(unsafeWindow.QT_deleteAllValues, unsafeWindow, {
		defineAs : "QT_deleteAllValues"
	});
}

function appendScript() {
	if (unsafeWindow.Game) {
		var QT_script = document.createElement('script');
		QT_script.type = 'text/javascript';
		QT_script.textContent = main_script.toString() + "\n main_script(" + JSON.stringify(DATA) + ");";
		document.body.appendChild(QT_script);
	} else {
		setTimeout(function () {
			appendScript();
		}, 100);
	}
}

appendScript();