FastRecall

FastRecall for Ogame: Allows you to recall fleets from the events list drop down bar

  1. // ==UserScript==
  2. // @name FastRecall
  3. // @namespace FastRecallNamespace
  4. // @author [TSN]Kanly
  5. // @include *.ogame.gameforge.com/game/*
  6. // @description FastRecall for Ogame: Allows you to recall fleets from the events list drop down bar
  7. // @version 1.6
  8. // ==/UserScript==
  9.  
  10. var scriptFunc = (function() {
  11. var Recall = {
  12. getMovement: true,
  13. getEvents: true,
  14. pendingMovement: false,
  15. pendingEvents: false,
  16. availableMovements: [],
  17. availableEvents: {},
  18. currentPage: "",
  19. universeFull: "",
  20. missionType: {expedition:15, deploy:4, acsAttack:2, attack:1},
  21.  
  22. init: function() {
  23. var observer = new MutationObserver(Recall.initAppendRecall);
  24. var target = document.getElementById('eventboxContent');
  25.  
  26. Recall.universeFull = document.getElementsByName("ogame-universe")[0].content;
  27. Recall.currentPage = (window.location+"").match(/page=[^&]+((?=&)|(?=#)|)/g)[0].replace("page=", "");
  28.  
  29. /* Disable FastRecall on fleet1/2/3 and movement pages */
  30. if (Recall.currentPage !== "movement" &&
  31. Recall.currentPage !== "fleet1" &&
  32. Recall.currentPage !== "fleet2" &&
  33. Recall.currentPage !== "fleet3") {
  34.  
  35. observer.observe(target, {childList: true});
  36.  
  37. /* If events are not hidden (Options->Display->Always show events */
  38. if ($('table#eventContent').exists()) {
  39. Recall.initAppendRecall();
  40. }
  41. }
  42. },
  43.  
  44. initAppendRecall: function(mutations) {
  45. if ($('table#eventContent').exists()) {
  46. /* Get the "fleet movement" page information only once - when the fleets eventbox is showen for the first time */
  47. if (Recall.getMovement === true && Recall.pendingMovement === false) {
  48. Recall.pendingMovement = true;
  49. Recall.getFleetMovement();
  50. }
  51.  
  52. /* Get a clean eventlist content only once.
  53. This is done because AGO or other tools might alter the original information (eg. change clocks values to local time)
  54. */
  55. if (Recall.getEvents === true && Recall.pendingEvents === false) {
  56. Recall.pendingEvents = true;
  57. Recall.getEventsList();
  58. }
  59.  
  60. if (Recall.getEvents === false && Recall.getMovement === false) {
  61. Recall.doAppendRecall();
  62. }
  63. }
  64. },
  65.  
  66. doAppendRecall: function() {
  67. if ($('table#eventContent').exists()) {
  68. Recall.appendEventlistReload();
  69.  
  70. $('table#eventContent tr[data-return-flight="false"]').each(function() {
  71. var row = $(this);
  72. var isAllianceAttack = row.hasClass('allianceAttack');
  73.  
  74. if (isAllianceAttack === false) {
  75. var missionType = parseInt(row.attr('data-mission-type'));
  76. var eventRowId;
  77.  
  78. if (missionType !== Recall.missionType.acsAttack)
  79. eventRowId = parseInt(row.attr('id').match(/\d+/)[0]);
  80. else
  81. eventRowId = parseInt(row.find('td.icon_movement span.tooltip').attr('data-federation-user-id').match(/\d+/)[0]);
  82.  
  83. if (Recall.availableEvents[eventRowId]) {
  84. var returnId = Recall.matchEventWithMovement(Recall.availableEvents[eventRowId]);
  85.  
  86. if (returnId !== "" && returnId !== "multipleMatch")
  87. row.append('<td class="oaf_recall_td"><a class="oaf_recall_icon icon_link" oaf_recall_id='+returnId+'></a></td>');
  88. }
  89. }
  90. });
  91.  
  92. $('.oaf_recall_icon').click(function(){
  93. var recallId = $(this).attr('oaf_recall_id');
  94. var url = 'http://'+Recall.universeFull+'/game/index.php?page=movement&return='+recallId;
  95.  
  96. $.get(url, function(response) {$('#eventHeader .icon_reload').click();});
  97. });
  98. }
  99. },
  100.  
  101. appendEventlistReload: function() {
  102. if (!window.AGO && $('#eventHeader .icon_reload.recall_eventlist_reload').exists() === false) {
  103. $('#eventHeader').prepend('<a href="javascript:void(0)"><span class="icon icon_reload recall_eventlist_reload"></span></a>').click(function(){
  104. $.get("/game/index.php?page=eventList&ajax=1", function (a) { $("#eventboxContent").html(a);});
  105. });
  106. }
  107. },
  108.  
  109. getFleetMovement: function() {
  110. /* Get the "fleet movement" page information; should be called only once */
  111. var url = 'http://'+Recall.universeFull+'/game/index.php?page=movement';
  112.  
  113. $.get(url, Recall.parseFleetMovement);
  114. },
  115.  
  116. parseFleetMovement: function(html) {
  117. /* get own fleet flights except returning ones */
  118. var page = $(html);
  119. Recall.availableMovements = [];
  120.  
  121. page.find('.fleetDetails[data-return-flight="false"]').each(function() {
  122. var item = $(this);
  123. var info = {};
  124.  
  125. info.arrivalTime = item.attr('data-arrival-time');
  126. info.originPosStr = item.find('.originCoords').text();
  127. info.destinationPosStr = item.find('.destinationCoords').text();
  128. info.returnId = item.attr('id').match(/\d+/g)[0];
  129. info.missionType = parseInt(item.attr('data-mission-type'));
  130.  
  131. var retTime = item.find('span.nextabsTime');
  132. if (retTime.exists())
  133. info.retClock = retTime.text().trim();
  134. else
  135. info.retClock = "none";
  136.  
  137. /* console.log("New movement: " + JSON.stringify(info)); */
  138. Recall.availableMovements.push(info);
  139. });
  140.  
  141. Recall.pendingMovement = false;
  142. Recall.getMovement = false;
  143.  
  144. /* On galaxy view: the miniFleetToken is invalidated after getting the fleetMovement page.
  145. As a result, the first spy attempt will fail ('an error has occured'). We get a valid token
  146. by sending an invalid spy request and using the newToken from the response.
  147. */
  148. if (Recall.currentPage === "galaxy") {
  149. var url = 'http://'+Recall.universeFull+'/game/index.php?page=minifleet&ajax=1';
  150. var data = 'mission=6&token=none&speed=10';
  151. $.post(url, data, function(resp){
  152. try {
  153. window.miniFleetToken = JSON.parse(resp).newToken;
  154. } catch(e) {}
  155. });
  156. }
  157.  
  158. Recall.doAppendRecall();
  159. },
  160.  
  161. getEventsList: function() {
  162. /* get eventlist content; should be called only once */
  163. $.get("/game/index.php?page=eventList&ajax=1", function (a) {
  164. var item = $('<div>'+a+'</div>');
  165. Recall.availableEvents = {};
  166.  
  167. item.find('table#eventContent tr[data-return-flight="false"]').each(function() {
  168. var row = $(this);
  169. var isFriendly = row.find('.countDown.friendly').exists();
  170. var isAllianceAttack = row.hasClass('allianceAttack');
  171.  
  172. if (isFriendly === true && isAllianceAttack === false) {
  173. var info = {};
  174. info.arrivalTime = row.attr('data-arrival-time');
  175. info.originPosStr = row.find('.coordsOrigin').text().trim();
  176. info.destinationPosStr = row.find('.destCoords').text().trim();
  177. info.missionType = parseInt(row.attr('data-mission-type'));
  178.  
  179. var eventRowId;
  180. if (info.missionType !== Recall.missionType.acsAttack) {
  181. eventRowId = parseInt(row.attr('id').match(/\d+/)[0]);
  182. }
  183. else {
  184. eventRowId = parseInt(row.find('td.icon_movement span.tooltip').attr('data-federation-user-id').match(/\d+/)[0]);
  185.  
  186. var unionName = row.attr('class').match(/union\d+/)[0];
  187. /* console.log(unionName + " " + eventRowId + " " + item.find('tr.partnerInfo.' + unionName).length); */
  188. if (unionName.indexOf("" + eventRowId) !== -1 && item.find('tr.partnerInfo.' + unionName).length === 1)
  189. info.missionType = Recall.missionType.attack;
  190. }
  191.  
  192. var pairRowId = eventRowId + (info.missionType === Recall.missionType.expedition ? 2 : 1);
  193. var retRow = item.find('#eventRow-'+pairRowId+'[data-return-flight="true"]');
  194.  
  195. if (retRow.exists()) {
  196. var retTime = retRow.attr('data-arrival-time');
  197. var origPosRet = retRow.find('.coordsOrigin').text().trim();
  198. var destPosRet = retRow.find('.destCoords').text().trim();
  199.  
  200. if (origPosRet === info.originPosStr && destPosRet === info.destinationPosStr) {
  201. info.retClock = retRow.find('td.arrivalTime').text().trim();
  202. }
  203. else {
  204. info.retClock = "none";
  205. }
  206. }
  207. else {
  208. info.retClock = "none";
  209. }
  210.  
  211. /* console.log("New event row: " + JSON.stringify(info)); */
  212. Recall.availableEvents[eventRowId] = info;
  213. }
  214. });
  215.  
  216. $("#eventboxContent").html(a);
  217. Recall.getEvents = false;
  218. Recall.pendingEvents = false;
  219. });
  220. },
  221.  
  222. matchEventWithMovement: function(evInfo) {
  223. var retVal = "";
  224. for (var m in Recall.availableMovements) {
  225. if (Recall.availableMovements.hasOwnProperty(m) === false)
  226. continue;
  227.  
  228. var mvInfo = Recall.availableMovements[m];
  229.  
  230. if (mvInfo.arrivalTime === evInfo.arrivalTime &&
  231. mvInfo.originPosStr === evInfo.originPosStr &&
  232. mvInfo.destinationCoords === evInfo.destinationCoords &&
  233. mvInfo.missionType === evInfo.missionType) {
  234.  
  235. if (mvInfo.missionType === Recall.missionType.deploy ||
  236. (mvInfo.retClock === evInfo.retClock && mvInfo.retClock !== "none")) {
  237.  
  238. if (retVal === "")
  239. retVal = mvInfo.returnId;
  240. else
  241. retVal = "multipleMatch";
  242. }
  243. }
  244. }
  245.  
  246. return retVal;
  247. }
  248. };
  249.  
  250. $.fn.exists = function () {
  251. return this.length !== 0;
  252. };
  253.  
  254. Recall.init();
  255.  
  256. }).toString();
  257.  
  258.  
  259. function injectScript (myFunc) {
  260. var script = document.createElement ("script");
  261. script.setAttribute ("type", "application/javascript");
  262. script.textContent = "(" + myFunc + ") ();";
  263. document.body.appendChild (script);
  264. }
  265.  
  266. function injectCss() {
  267. var recallImage = "data:image/gif;base64,R0lGODlhEAAQAKIAAISbrAAAAP///2+JnVx2iwAAAAAAAAAAACH5BAAAAAAALAAAAAAQABAAAAMqGLTcrS7KSautIut9mejLtwwkKZTliQ5Atg4qus1x2dbviud875eBHzABADs=";
  268. var recallCss = '.oaf_recall_icon {background-image: url('+recallImage+'); background-repeat: no-repeat !important;} #eventHeader .recall_eventlist_reload {position: absolute; left: 14px; margin: 4px 0;}';
  269. var style = document.createElement('style');
  270. style.type = 'text/css';
  271. style.innerHTML = recallCss;
  272.  
  273. document.getElementsByTagName("head")[0].appendChild(style);
  274. }
  275.  
  276. if (document.body) {
  277. injectScript(scriptFunc);
  278. injectCss();
  279. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址