QT Framework for Grepolis

A script framework for Grepolis

28.07.2014 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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.01.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 : {
			test : {
				teststring : 'Sprache wurde erkannt'
			}
		},
		en : {
			test : {
				teststring : 'Language detected'
			}
		}
	};
	
	/************************************************************************
	 * Images
	 ***********************************************************************/
	QT.Images = {};
	
	/************************************************************************
	 * Links
	 ***********************************************************************/
	QT.Links = {};
	
	/************************************************************************
	 * Settings
	 ***********************************************************************/
	QT.Settings = {
		values : {
				"messageOpenAlert" : true,
				"startFunction" : true,
		},
		save : function (name, value) {
			QT_saveValue(name, value);
		},
		delete : function (name) {
			QT_deleteValue(name);
		},
		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();
			}
		}
	};
	
	/************************************************************************
	 * Functions
	 ***********************************************************************/
	QT.Functions = {
		messageOpenAlert : function () {
			alert("Die Nachrichten 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_delete">Delete</button></div>');
			$("#qt_save").click(function () {
				QT.Settings.save("messageOpenAlert", false);
			});
			$("#qt_delete").click(function () {
				QT.Settings.delete("messageOpenAlert");
			});
		}
	};
	
	/************************************************************************
	 * Observer
	 ***********************************************************************/
	$.Observer(GameEvents.game.load).subscribe('DIO_START', 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);
			}
		});
	});
}


/************************************************************************
 * Startup 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_deleteValue = function (name){
    setTimeout(function(){
        GM_deleteValue(name);
		window.location.reload();
    },0, name);
};

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

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();