// ==UserScript== // @name Grepolis Academy Overview // @name:de Grepolis Akademie Übersicht // @name:en Grepolis Academy Overview // @namespace grepolis // @description Grepolis: List all researches of all towns // @description:de Grepolis: Eine Übersicht über alle Forschungen aller Städte. // @description:en Grepolis: List all researches of all towns // @include http://*.grepolis.* // @exclude http://forum.*.grepolis.* // @exclude http://wiki.*.grepolis.* // @icon http://s3.amazonaws.com/uso_ss/icon/185038/large.png?1385676234 // @version 2.14 // @grant GM_listValues // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @grant GM_info // @grant GM_xmlhttpRequest // @downloadURL none // ==/UserScript== /************************************************************************ * Main Script ***********************************************************************/ function XR_main_script(DATA) { /************************************************************************ * Global variables ***********************************************************************/ var XR = {}; 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; $(".tb_activities").css("left","227px"); $(".toolbar_buttons").append('\
\
\
\
\
\ '); $("#BTN_academyoverview").click(function() { XR.Functions.academyOverview(); }); /************************************************************************ * Languages ***********************************************************************/ XR.Lang = { get : function (a, b) { if (XR.Lang[mID] != undefined && XR.Lang[mID][a] != undefined && XR.Lang[mID][a][b] != undefined) { return XR.Lang[mID][a][b] } else if (XR.Lang[mID] != undefined && XR.Lang[mID][a] != undefined) { return XR.Lang[mID][a] } else if (XR.Lang["en"] != undefined && XR.Lang["en"][a] != undefined && XR.Lang["en"][a][b] != undefined) { return XR.Lang.en[a][b] } else { return XR.Lang.en[a] } }, de : { meta : { lang : 'deutsch' }, academyoverview :"Akademie-Übersicht", research_technology :"Technologie erforschen", reset_technology :"Forschung zurücksetzen", confirm_reset_technology :"Bestätigungsabfrage beim Zurücksetzen einer Forschung", save :"Speichern" }, en : { meta : { lang : 'english' }, academyoverview :"Academy Overview", research_technology :"Research technology", reset_technology :"Reset technology", confirm_reset_technology :"Confirmation prompt when reset a technology", save :"Save" } }; /************************************************************************ * Ajax Call functions ***********************************************************************/ XR.CallAjaxFunction = { player : { index : function () { XR.Functions.SettingsWindow(); }, } }; /************************************************************************ * Functions ***********************************************************************/ XR.Functions = { academyOverview : function () { var wnd = GPWindowMgr.Create(GPWindowMgr.TYPE_XR_ACADEMYOVERVIEW) || GPWindowMgr.getOpenFirst(GPWindowMgr.TYPE_XR_ACADEMYOVERVIEW); var research_ids = []; for (i=1; i<=34; i=i+3) { $.each(GameData.researches, function () { if ($(this)[0].building_dependencies.academy==i) { research_ids.push($(this)[0].id); } }); } var factor = Math.min(Math.max(Math.ceil(research_ids.length/3), 10), 13); wincontent = '\ \
\
\ \
\
    \
\
\
\
'; wnd.setContent(wincontent); if (research_ids.length>0) { $("#header").append('
'); $("#moveleft").click(function(){ if (parseInt($("#academyoverview_header").css("left"))<0) { $(".academyoverview_movetab").animate({left:'+='+factor*46+'px'},"slow"); } else { $(".academyoverview_movetab").animate({left:'-'+(Math.ceil(research_ids.length/factor)-1)*factor*46+'px'},"slow"); } }); $("#moveright").click(function(){ if (parseInt($("#academyoverview_header").css("left"))<=(Math.ceil(research_ids.length/factor)-1)*factor*-46) { $(".academyoverview_movetab").animate({left:'0px'},"slow"); } else { $(".academyoverview_movetab").animate({left:'-='+factor*46+'px'},"slow"); } }); } $.each(research_ids, function(i, val) { if (research_ids[i]=="take_over") { $("#academyoverview_header").append('
'); } else { $("#academyoverview_header").append('\
\
\
'+GameData.researches[research_ids[i]].research_points+'
\
\
\ '); } }); for (i=research_ids.length; i<=Math.floor(research_ids.length/factor+1)*factor; i++) { $("#academyoverview_header").append('
'); } XRTownNames = []; for (i=0; i\
\ '+XRtownname+'\
'+XRacademypoints+' P.
\
\
\
\
\
\
\
\
\ \ '); for (j=0; j\
\
\
\ \ '); } else if (ITowns.towns[XRtownid].researches().attributes[research_ids[j]]==true) { XRacademypoints -= GameData.researches[research_ids[j]].research_points; $("#XRpoints"+XRtownid).html(XRacademypoints+' P.'); XR_researchDown = (DATA.XR_reset_technology!=="checked") ? '' : '
'; $("#researches_"+XRtownid).append('\
\
\
'+XR_researchDown+'
\
\
\ '); } else { XR_researchUp = (DATA.XR_research_technology!=="checked" || XRacademypoints < GameData.researches[research_ids[j]].research_points) ? '' : '
'; $("#researches_"+XRtownid).append('\
\
\
'+XR_researchUp+'
\
\
\ '); } } if (liclass=="even") { liclass = "odd"; } else { liclass = "even"; } break; } } } $(".research40x40").css("background-repeat","no-repeat"); $(".townlist_width").css("width",Math.round(200+((13-factor)*46)).toString()+"px"); $(".XRresearchUp").click(function() { console.log($(this).attr("id")+" Up"); }); $(".XRresearchDown").click(function() { console.log($(this).attr("id")+" Down"); }); }, SettingsWindow : function () { if ($(".XR_settings").length==0) { $("DIV.settings-menu ul:last").append('\
  • \ \ '+XR.Lang.get("academyoverview")+'\
  • \ ') $(".XR_settings").click(function() { console.log("XR_settings"); if ($("#settings_form").length == 0) { $(".settings-container").html('\
    \
    \
    \
    '+XR.Lang.get("academyoverview")+'
    \
    \
    '+XR.Lang.get("research_technology")+'
    \
    \
    \
    '+XR.Lang.get("reset_technology")+'
    \
    \
    \
    '+XR.Lang.get("confirm_reset_technology")+'
    \
    \
    \
    \
    \ '); } else { $("#s_email_notifications").hide(); $("#s_notifications").hide(); $("#s_windows_mgr").hide(); $("#s_buffering").hide(); $("#s_map").hide(); $("#s_timezone").hide(); $("#s_city_preview").hide(); $("#s_confirmations").hide(); $("#s_sound_config").hide(); $("#settings_form").append('\
    \
    '+XR.Lang.get("academyoverview")+'
    \
    \
    '+XR.Lang.get("research_technology")+'
    \
    \
    \
    '+XR.Lang.get("reset_technology")+'
    \
    \
    \
    '+XR.Lang.get("confirm_reset_technology")+'
    \
    \
    \ '); } $(".research_technology").click(function() { if ($(this).hasClass("checked")) { $(this).removeClass("checked"); DATA.XR_research_technology = ""; XR_setValue("XR_research_technology", ""); } else { $(this).addClass("checked"); DATA.XR_research_technology = "checked"; XR_setValue("XR_research_technology", "checked"); } }); $(".reset_technology").click(function() { if ($(this).hasClass("checked")) { $(this).removeClass("checked"); DATA.XR_reset_technology = ""; XR_setValue("XR_reset_technology", ""); } else { $(this).addClass("checked"); DATA.XR_reset_technology = "checked"; XR_setValue("XR_reset_technology", "checked"); } }); $(".confirm_reset_technology").click(function() { if ($(this).hasClass("checked")) { $(this).removeClass("checked"); DATA.XR_confirm_reset_technology = ""; XR_setValue("XR_confirm_reset_technology", ""); } else { $(this).addClass("checked"); DATA.XR_confirm_reset_technology = "checked"; XR_setValue("XR_confirm_reset_technology", "checked"); } }); }); } }, mutationobserver : function () { var observer = new MutationObserver(function (mutations) { }); observer.observe($('body').get(0), { attributes : false, childList : true, characterData : false }); }, windowmanager : function () { //Academyoverview function WndHandlerXRacademyoverview(wndhandle) { this.wnd = wndhandle; } Function.prototype.inherits.call(WndHandlerXRacademyoverview, WndHandlerDefault); WndHandlerXRacademyoverview.prototype.getDefaultWindowOptions = function () { return { position : ["center","center"], width : 850, height : 500, minimizable : true, title : XR.Lang.get("academyoverview") }; }; GPWindowMgr.addWndType("XR_ACADEMYOVERVIEW","xracademyoverview", WndHandlerXRacademyoverview, 1); } }; /************************************************************************ * Observer ***********************************************************************/ $.Observer(GameEvents.game.load).subscribe('XR', function (e, data) { XR.Functions.mutationobserver(); XR.Functions.windowmanager(); $(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); console.log(b+" "+c); if (b in XR.CallAjaxFunction && c in XR.CallAjaxFunction[b]) { XR.CallAjaxFunction[b][c](event, xhr, settings); } }); }); } /************************************************************************ * Start Method ***********************************************************************/ var DATA = { script_version : GM_info.script.version, XR_research_technology : (GM_getValue("XR_research_technology") !== undefined ? GM_getValue("XR_research_technology") : "checked"), XR_reset_technology : (GM_getValue("XR_reset_technology") !== undefined ? GM_getValue("XR_reset_technology") : ""), XR_confirm_reset_technology : (GM_getValue("XR_confirm_reset_technology") !== undefined ? GM_getValue("XR_confirm_reset_technology") : "checked") }; unsafeWindow.XR_setValue = function (name, val) { setTimeout(function () { GM_setValue(name, val); }, 0); }; if (typeof exportFunction == 'function') { exportFunction(unsafeWindow.XR_setValue, unsafeWindow, { defineAs : "XR_setValue" }); } function appendScript() { if (unsafeWindow.Game) { var XR_script = document.createElement('script'); XR_script.type = 'text/javascript'; XR_script.id ="XR_script"; XR_script.textContent = XR_main_script.toString() +"\n XR_main_script(" + JSON.stringify(DATA) +");"; document.body.appendChild(XR_script); } else if (mID=="") { setTimeout(function () { appendScript(); }, 100); } } appendScript();