Grepolis Academy Overview

Grepolis: List all researches of all towns

  1. // ==UserScript==
  2. // @name Grepolis Academy Overview
  3. // @name:de Grepolis Akademie Übersicht
  4. // @name:en Grepolis Academy Overview
  5. // @namespace grepolis
  6. // @description Grepolis: List all researches of all towns
  7. // @description:de Grepolis: Eine Übersicht über alle Forschungen aller Städte.
  8. // @description:en Grepolis: List all researches of all towns
  9. // @include http://*.grepolis.*
  10. // @exclude http://forum.*.grepolis.*
  11. // @exclude http://wiki.*.grepolis.*
  12. // @icon http://s3.amazonaws.com/uso_ss/icon/185038/large.png?1385676234
  13. // @version 2.15
  14. // @grant GM_listValues
  15. // @grant GM_getValue
  16. // @grant GM_setValue
  17. // @grant GM_deleteValue
  18. // @grant GM_info
  19. // @grant GM_xmlhttpRequest
  20. // ==/UserScript==
  21.  
  22. /************************************************************************
  23. * Main Script
  24. ***********************************************************************/
  25. function XR_main_script(DATA) {
  26. /************************************************************************
  27. * Global variables
  28. ***********************************************************************/
  29. var XR = {};
  30. var wID = Game.world_id;
  31. var mID = Game.market_id;
  32. var aID = Game.alliance_id;
  33. var sID = Game.player_id;
  34. var pName = Game.player_name;
  35.  
  36. $(".tb_activities").css("left","227px");
  37.  
  38. $(".toolbar_buttons").append('\
  39. <div class="toolbar_button academy">\
  40. <div id="BTN_academyoverview" class="icon" style="background:url(http://gpde.innogamescdn.com/images/game/academy/points_25x25.png) no-repeat scroll 0 0 rgba(0, 0, 0, 0); margin:2px;">\
  41. <div class="js-caption"></div>\
  42. </div>\
  43. </div>\
  44. ');
  45. $("#BTN_academyoverview").click(function() {
  46. XR.Functions.academyOverview();
  47. });
  48.  
  49. /************************************************************************
  50. * Languages
  51. ***********************************************************************/
  52. XR.Lang = {
  53. get : function (a, b) {
  54. if (XR.Lang[mID] !== undefined && XR.Lang[mID][a] !== undefined && XR.Lang[mID][a][b] !== undefined) {
  55. return XR.Lang[mID][a][b];
  56. } else if (XR.Lang[mID] !== undefined && XR.Lang[mID][a] !== undefined) {
  57. return XR.Lang[mID][a];
  58. } else if (XR.Lang.en !== undefined && XR.Lang.en[a] !== undefined && XR.Lang.en[a][b] !== undefined) {
  59. return XR.Lang.en[a][b];
  60. } else {
  61. return XR.Lang.en[a];
  62. }
  63. },
  64. de : {
  65. meta : {
  66. lang : 'deutsch'
  67. },
  68. academyoverview :"Akademie-Übersicht",
  69. research_technology :"Technologie erforschen",
  70. reset_technology :"Forschung zurücksetzen",
  71. confirm_reset_technology :"Bestätigungsabfrage beim Zurücksetzen einer Forschung",
  72. save :"Speichern"
  73. },
  74. en : {
  75. meta : {
  76. lang : 'english'
  77. },
  78. academyoverview :"Academy Overview",
  79. research_technology :"Research technology",
  80. reset_technology :"Reset technology",
  81. confirm_reset_technology :"Confirmation prompt when reset a technology",
  82. save :"Save"
  83. }
  84. };
  85.  
  86. /************************************************************************
  87. * Ajax Call functions
  88. ***********************************************************************/
  89. XR.CallAjaxFunction = {
  90. player : {
  91. index : function () {
  92. XR.Functions.SettingsWindow();
  93. },
  94. },
  95. notify : {
  96. fetch : function () {
  97. console.log("fetch");
  98. console.log(document.URL);
  99. },
  100. }
  101. };
  102.  
  103. /************************************************************************
  104. * Functions
  105. ***********************************************************************/
  106. XR.Functions = {
  107. academyOverview : function () {
  108. var wnd = GPWindowMgr.Create(GPWindowMgr.TYPE_XR_ACADEMYOVERVIEW) || GPWindowMgr.getOpenFirst(GPWindowMgr.TYPE_XR_ACADEMYOVERVIEW);
  109. var research_ids = [];
  110. for (i=1; i<=34; i=i+3) {
  111. $.each(GameData.researches, function () {
  112. if ($(this)[0].building_dependencies.academy==i) {
  113. research_ids.push($(this)[0].id);
  114. }
  115. });
  116. }
  117.  
  118. var factor = Math.min(Math.max(Math.ceil(research_ids.length/3), 10), 13);
  119. wincontent = '\
  120. <style type="text/css">\
  121. .fleft { float:left; }\
  122. .cleft { clear:left; }\
  123. .XRresearchHeader { float:left; border: 1px solid #000000; margin: 0 2px; }\
  124. .XRresearch { float:left; margin: 0 2px; }\
  125. .XRresearchleft { float:left; width:2px; height:24px; background:url(http://gpde.innogamescdn.com/images/game/survey/survey_sprite.png) no-repeat scroll 0px -39px rgba(0, 0, 0, 0); }\
  126. .XRresearchright { float:left; width:2px; height:24px; background:url(http://gpde.innogamescdn.com/images/game/survey/survey_sprite.png) no-repeat scroll -360px -39px rgba(0, 0, 0, 0); }\
  127. .XRresearchtrue { float:left; width:38px; height:24px; background:url(http://gpde.innogamescdn.com/images/game/survey/survey_sprite.png) no-repeat scroll -321px -39px rgba(0, 0, 0, 0); position:relative; }\
  128. .XRresearchfalse { float:left; width:38px; height:24px; background:url(http://gpde.innogamescdn.com/images/game/survey/survey_sprite.png) no-repeat scroll -2px -39px rgba(0, 0, 0, 0); position:relative; }\
  129. .XRresearchgrey { float:left; width:38px; height:24px; background:url(http://gpde.innogamescdn.com/images/game/survey/survey_sprite.png) no-repeat scroll -2px 0 / auto 36px rgba(0, 0, 0, 0); opacity:0.8; position:relative; }\
  130. .XRresearchUp { position:absolute; bottom:2px; right:0px; cursor:pointer; width:15px; height:15px; background:url(http://gpde.innogamescdn.com/images/game/academy/up.png) no-repeat scroll 0 0 rgba(0, 0, 0, 0); background-size:15px auto; }\
  131. .XRresearchUp:hover { background-position:0 -15px; }\
  132. .XRresearchDown { position:absolute; bottom:2px; right:0px; cursor:pointer; width:15px; height:15px; background:url(http://gpde.innogamescdn.com/images/game/academy/down.png) no-repeat scroll 0 0 rgba(0, 0, 0, 0); background-size:15px auto; }\
  133. .XRresearchDown:hover { background-position:0 -15px; }\
  134. </style>\
  135. <div style="margin-bottom:5px">\
  136. <div style="width:850px; height:440px; overflow:hidden; background:url(http://gpde.innogamescdn.com/images/game/overviews/fixed_table_header_bg.jpg) repeat-x scroll 0 0 rgba(0, 0, 0, 0)">\
  137. <div id="header">\
  138. <div class="townlist_width" style="width:200px; height:40px; float:left;"></div>\
  139. </div>\
  140. <div id="datalist" style="width:850px; height:400px; overflow:auto;">\
  141. <ul id="academyoverview_townlist" class="game_list">\
  142. </ul>\
  143. </div>\
  144. </div>\
  145. </div>';
  146. wnd.setContent(wincontent);
  147. if (research_ids.length>0) {
  148. $("#header").append('<a href="#" id="moveleft" class="game_arrow_left" style="margin:11px 4px 0 0;"></a><div id="academyoverview_container" style="float:left; width:'+Math.round(factor*46).toString()+'px; height:42px; overflow:hidden;"><div id="academyoverview_header" class="academyoverview_movetab" style="width:'+Math.round(research_ids.length*46).toString()+'px; height:42px; position:relative; left:0px;"></div></div><a href="#" id="moveright" class="game_arrow_right" style="margin:11px 0 0 4px;"></a>');
  149. $("#moveleft").click(function(){
  150. if (parseInt($("#academyoverview_header").css("left"))<0) {
  151. $(".academyoverview_movetab").animate({left:'+='+factor*46+'px'},"slow");
  152. } else {
  153. $(".academyoverview_movetab").animate({left:'-'+(Math.ceil(research_ids.length/factor)-1)*factor*46+'px'},"slow");
  154. }
  155. });
  156. $("#moveright").click(function(){
  157. if (parseInt($("#academyoverview_header").css("left"))<=(Math.ceil(research_ids.length/factor)-1)*factor*-46) {
  158. $(".academyoverview_movetab").animate({left:'0px'},"slow");
  159. } else {
  160. $(".academyoverview_movetab").animate({left:'-='+factor*46+'px'},"slow");
  161. }
  162. });
  163. }
  164.  
  165. $.each(research_ids, function(i, val) {
  166. if (research_ids[i]=="take_over") {
  167. $("#academyoverview_header").append('<div class="research_box XRresearchHeader"><div class="research_icon research40x40 '+research_ids[i]+'_old"></div></div>');
  168. } else {
  169. $("#academyoverview_header").append('\
  170. <div class="research_box XRresearchHeader">\
  171. <div class="research_icon research40x40 '+research_ids[i]+'" style="position:relative;">\
  172. <div style="position:absolute; bottom:0px; right:2px; color:#FFF; text-shadow:1px 1px 0 #000; font-family:Verdana; font-size:14px; font-weight:700;">'+GameData.researches[research_ids[i]].research_points+'</div>\
  173. </div>\
  174. </div>\
  175. ');
  176. }
  177. });
  178. for (i=research_ids.length; i<=Math.floor(research_ids.length/factor+1)*factor; i++) {
  179. $("#academyoverview_header").append('<div class="research_box XRresearchHeader" style="border-color:transparent;"><div class="research_icon research40x40" style="background-position:-580px -580px;"></div></div>');
  180. }
  181.  
  182. XRTownNames = [];
  183. for (i=0; i<ITowns.towns_collection.length; i++) {
  184. XRTownNames.push(ITowns.towns_collection.models[i].attributes.name);
  185. }
  186. XRTownNames.sort();
  187.  
  188. var liclass = "even";
  189. for (k=0; k<XRTownNames.length; k++) {
  190. for (i=0; i<ITowns.towns_collection.length; i++) {
  191. if (XRTownNames[k] == ITowns.towns_collection.models[i].attributes.name) {
  192. XRtownid = ITowns.towns_collection.models[i].attributes.id;
  193. XRtownname = ITowns.towns_collection.models[i].attributes.name;
  194. XRtownlink = ITowns.towns_collection.models[i].attributes.link_fragment;
  195. XRacademypoints = (ITowns.getTown(XRtownid).getBuildings().attributes.academy * GameDataResearches.getResearchPointsPerAcademyLevel()) + (ITowns.getTown(XRtownid).getBuildings().attributes.library * GameDataResearches.getResearchPointsPerLibraryLevel());
  196. for (j=0; j<research_ids.length; j++) {
  197. if (ITowns.towns[XRtownid].researches().attributes[research_ids[j]]===true) {
  198. XRacademypoints -= GameData.researches[research_ids[j]].research_points;
  199. }
  200. }
  201. /* $("#XRpoints"+XRtownid).html(XRacademypoints+' P.');*/
  202. $("#academyoverview_townlist").append('\
  203. <li class="'+liclass+'">\
  204. <div class="townlist_width" style="width:200px; float:left; margin-top:2px;">\
  205. <a href="#'+XRtownlink+'" class="gp_town_link">'+XRtownname+'</a>\
  206. <div id="XRpoints'+XRtownid+'" style="float:right; width:40px; height:20px; font-size:12px; line-height:20px;">'+XRacademypoints+' P.</div>\
  207. <div style="clear: both;"></div>\
  208. </div>\
  209. <div style="float:left; width:20px; height:20px; background:url(http://gpde.innogamescdn.com/images/game/academy/points_25x25.png) no-repeat;"></div>\
  210. <div style="float:left; width:'+Math.round(factor*46).toString()+'px; height:24px; overflow:hidden;">\
  211. <div id="researches_'+XRtownid+'" class="academyoverview_movetab" style="width:'+Math.round(research_ids.length*46).toString()+'px; height:24px; position:relative; left:0px;">\
  212. </div>\
  213. </div>\
  214. <div style="clear:left;"></div>\
  215. </li>\
  216. ');
  217. for (j=0; j<research_ids.length; j++) {
  218. if (ITowns.towns[XRtownid].buildings().attributes.academy < GameData.researches[research_ids[j]].building_dependencies.academy) {
  219. $("#researches_"+XRtownid).append('\
  220. <div class="XRresearch">\
  221. <div class="XRresearchleft"></div>\
  222. <div class="XRresearchgrey"></div>\
  223. <div class="XRresearchright"></div>\
  224. </div>\
  225. ');
  226. } else if (ITowns.towns[XRtownid].researches().attributes[research_ids[j]]===true) {
  227. XR_researchDown = (DATA.XR_reset_technology!=="checked") ? '' : '<div id="DOWN_'+XRtownid+'_'+research_ids[j]+'" class="XRresearchDown"></div>';
  228. $("#researches_"+XRtownid).append('\
  229. <div class="XRresearch">\
  230. <div class="XRresearchleft"></div>\
  231. <div class="XRresearchtrue">'+XR_researchDown+'</div>\
  232. <div class="XRresearchright"></div>\
  233. </div>\
  234. ');
  235. } else {
  236. XR_researchUp = (DATA.XR_research_technology!=="checked" || XRacademypoints < GameData.researches[research_ids[j]].research_points) ? '' : '<div id="UP_'+XRtownid+'_'+research_ids[j]+'" class="XRresearchUp"></div>';
  237. $("#researches_"+XRtownid).append('\
  238. <div class="XRresearch">\
  239. <div class="XRresearchleft"></div>\
  240. <div class="XRresearchfalse">'+XR_researchUp+'</div>\
  241. <div class="XRresearchright"></div>\
  242. </div>\
  243. ');
  244. }
  245. }
  246. if (liclass=="even") { liclass = "odd"; } else { liclass = "even"; }
  247. break;
  248. }
  249. }
  250. }
  251. $(".research40x40").css("background-repeat","no-repeat");
  252. $(".townlist_width").css("width",Math.round(200+((13-factor)*46)).toString()+"px");
  253. $(".XRresearchUp").click(function() {
  254. console.log($(this).attr("id")+" Up");
  255. splitid = $(this).attr("id").split("_");
  256. for (i=0; i<splitid.length; i++) {
  257. console.log(splitid[i]);
  258. }
  259. thistownid = splitid[1];
  260. thisresearchid = '';
  261. for (i=2; i<splitid.length; i++) {
  262. if (i>2) {
  263. thisresearchid += '_'+splitid[i];
  264. } else {
  265. thisresearchid += splitid[i];
  266. }
  267. }
  268. $.ajax({
  269. type: "POST",
  270. url: "/game/frontend_bridge?town_id="+ thistownid + "&action=execute&h="+ Game.csrfToken,
  271. data:
  272. 'json=%7B%22model_url%22%3A%22ResearchOrder%22%2C%22action_name%22%3A%22research%22%2C%22arguments%22%3A%7B%22id%22%3A%22'+thisresearchid+'%22%7D%2C%22town_id%22%3A'+thistownid+'%2C%22nl_init%22%3Atrue%7D'
  273. }).done(function (data) {
  274. console.log(data);
  275. $("#UP_"+thistownid+"_"+thisresearchid).parent().removeClass("XRresearchfalse").addClass("XRresearchtrue");
  276. $("#UP_"+thistownid+"_"+thisresearchid).remove();
  277. });
  278. console.log($(this).attr("id")+" Up");
  279. });
  280. $(".XRresearchDown").click(function() {
  281. console.log($(this).attr("id")+" Down");
  282. });
  283. },
  284. SettingsWindow : function () {
  285. if ($(".XR_settings").length===0) {
  286. $("DIV.settings-menu ul:last").append('\
  287. <li class="with-icon">\
  288. <img class="support-menu-item-icon XR_settings" src="http://gpde.innogamescdn.com/images/game/academy/points_25x25.png" style="width:20px; height:15px; vertical-align:bottom;">\
  289. <a href="#" class="XR_settings">'+XR.Lang.get("academyoverview")+'</a>\
  290. </li>\
  291. ');
  292. $(".XR_settings").click(function() {
  293. console.log("XR_settings");
  294. if ($("#settings_form").length === 0) {
  295. $(".settings-container").html('\
  296. <div id="player_settings">\
  297. <form id="settings_form" method="post" action="javascript:void(0)">\
  298. <div id="s_academy_overview" class="section" style="display: block;">\
  299. <div class="game_header bold">'+XR.Lang.get("academyoverview")+'</div>\
  300. <div class="checkbox_new research_technology '+DATA.XR_research_technology+'">\
  301. <div class="cbx_icon XR_cbox"></div><div class="cbx_caption">'+XR.Lang.get("research_technology")+'</div>\
  302. </div>\
  303. <div class="checkbox_new reset_technology '+DATA.XR_reset_technology+'">\
  304. <div class="cbx_icon XR_cbox"></div><div class="cbx_caption">'+XR.Lang.get("reset_technology")+'</div>\
  305. </div>\
  306. <div style="margin-left:20px;" class="checkbox_new confirm_reset_technology '+DATA.XR_confirm_reset_technology+'">\
  307. <div class="cbx_icon XR_cbox"></div><div class="cbx_caption">'+XR.Lang.get("confirm_reset_technology")+'</div>\
  308. </div>\
  309. </div>\
  310. </form>\
  311. </div>\
  312. ');
  313. } else {
  314. $("#s_email_notifications").hide();
  315. $("#s_notifications").hide();
  316. $("#s_windows_mgr").hide();
  317. $("#s_buffering").hide();
  318. $("#s_map").hide();
  319. $("#s_timezone").hide();
  320. $("#s_city_preview").hide();
  321. $("#s_confirmations").hide();
  322. $("#s_sound_config").hide();
  323. $("#settings_form").append('\
  324. <div id="s_academy_overview" class="section" style="display: block;">\
  325. <div class="game_header bold">'+XR.Lang.get("academyoverview")+'</div>\
  326. <div class="checkbox_new research_technology '+DATA.XR_research_technology+'">\
  327. <div class="cbx_icon XR_cbox"></div><div class="cbx_caption">'+XR.Lang.get("research_technology")+'</div>\
  328. </div>\
  329. <div class="checkbox_new reset_technology '+DATA.XR_reset_technology+'">\
  330. <div class="cbx_icon XR_cbox"></div><div class="cbx_caption">'+XR.Lang.get("reset_technology")+'</div>\
  331. </div>\
  332. <div style="margin-left:20px;" class="checkbox_new confirm_reset_technology '+DATA.XR_confirm_reset_technology+'">\
  333. <div class="cbx_icon XR_cbox"></div><div class="cbx_caption">'+XR.Lang.get("confirm_reset_technology")+'</div>\
  334. </div>\
  335. </div>\
  336. ');
  337. }
  338. $(".research_technology").click(function() {
  339. if ($(this).hasClass("checked")) {
  340. $(this).removeClass("checked");
  341. DATA.XR_research_technology = "";
  342. XR_setValue("XR_research_technology", "");
  343. } else {
  344. $(this).addClass("checked");
  345. DATA.XR_research_technology = "checked";
  346. XR_setValue("XR_research_technology", "checked");
  347. }
  348. });
  349. $(".reset_technology").click(function() {
  350. if ($(this).hasClass("checked")) {
  351. $(this).removeClass("checked");
  352. DATA.XR_reset_technology = "";
  353. XR_setValue("XR_reset_technology", "");
  354. } else {
  355. $(this).addClass("checked");
  356. DATA.XR_reset_technology = "checked";
  357. XR_setValue("XR_reset_technology", "checked");
  358. }
  359. });
  360. $(".confirm_reset_technology").click(function() {
  361. if ($(this).hasClass("checked")) {
  362. $(this).removeClass("checked");
  363. DATA.XR_confirm_reset_technology = "";
  364. XR_setValue("XR_confirm_reset_technology", "");
  365. } else {
  366. $(this).addClass("checked");
  367. DATA.XR_confirm_reset_technology = "checked";
  368. XR_setValue("XR_confirm_reset_technology", "checked");
  369. }
  370. });
  371. });
  372. }
  373. },
  374. mutationobserver : function () {
  375. var observer = new MutationObserver(function (mutations) {
  376. });
  377. observer.observe($('body').get(0), {
  378. attributes : false,
  379. childList : true,
  380. characterData : false
  381. });
  382. },
  383. windowmanager : function () {
  384. //Academyoverview
  385. function WndHandlerXRacademyoverview(wndhandle) {
  386. this.wnd = wndhandle;
  387. }
  388. Function.prototype.inherits.call(WndHandlerXRacademyoverview, WndHandlerDefault);
  389. WndHandlerXRacademyoverview.prototype.getDefaultWindowOptions = function () {
  390. return {
  391. position : ["center","center"],
  392. width : 850,
  393. height : 500,
  394. minimizable : true,
  395. title : XR.Lang.get("academyoverview")
  396. };
  397. };
  398. GPWindowMgr.addWndType("XR_ACADEMYOVERVIEW","xracademyoverview", WndHandlerXRacademyoverview, 1);
  399. }
  400. };
  401.  
  402. /************************************************************************
  403. * Observer
  404. ***********************************************************************/
  405. $.Observer(GameEvents.game.load).subscribe('XR', function (e, data) {
  406. XR.Functions.mutationobserver();
  407. XR.Functions.windowmanager();
  408. $(document).ajaxComplete(function (event, xhr, settings) {
  409. var a = settings.url.split("?");
  410. var b = a[0].substr(6);
  411. var c = a[1].split("&")[1].substr(7);
  412. console.log(b+" "+c);
  413. if (b in XR.CallAjaxFunction && c in XR.CallAjaxFunction[b]) {
  414. XR.CallAjaxFunction[b][c](event, xhr, settings);
  415. }
  416. });
  417. });
  418. }
  419.  
  420. /************************************************************************
  421. * Start Method
  422. ***********************************************************************/
  423. var DATA = {
  424. script_version : GM_info.script.version,
  425. XR_research_technology : (GM_getValue("XR_research_technology") !== undefined ? GM_getValue("XR_research_technology") : "checked"),
  426. XR_reset_technology : (GM_getValue("XR_reset_technology") !== undefined ? GM_getValue("XR_reset_technology") : ""),
  427. XR_confirm_reset_technology : (GM_getValue("XR_confirm_reset_technology") !== undefined ? GM_getValue("XR_confirm_reset_technology") : "checked")
  428. };
  429.  
  430. unsafeWindow.XR_setValue = function (name, val) {
  431. setTimeout(function () {
  432. GM_setValue(name, val);
  433. }, 0);
  434. };
  435.  
  436. if (typeof exportFunction == 'function') {
  437. exportFunction(unsafeWindow.XR_setValue, unsafeWindow, {
  438. defineAs : "XR_setValue"
  439. });
  440. }
  441.  
  442. function appendScript() {
  443. if (unsafeWindow.Game) {
  444. var XR_script = document.createElement('script');
  445. XR_script.type = 'text/javascript';
  446. XR_script.id ="XR_script";
  447. XR_script.textContent = XR_main_script.toString() +"\n XR_main_script(" + JSON.stringify(DATA) +");";
  448. document.body.appendChild(XR_script);
  449. } else if (mID==="") {
  450. setTimeout(function () {
  451. appendScript();
  452. }, 100);
  453. }
  454. }
  455.  
  456. appendScript();