WF Explorer Next Planet Button

Adds a next planet button for probes which launches fleet to next planet. For www.war-facts.com .

当前为 2015-05-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WF Explorer Next Planet Button
  3. // @namespace https://greasyfork.org/en/users/10321-nikitas
  4. // @description Adds a next planet button for probes which launches fleet to next planet. For www.war-facts.com .
  5. // @include http://*.war-facts.com/fleet.php*
  6. // @version 4
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. //Configuration Options:
  11.  
  12. //Change this if you do not want Auto Launch when Next Button is Pressed, or if you don't want to Auto Select Next Explorer
  13. unsafeWindow.AutoLaunch = true;
  14. unsafeWindow.AutoSelectNextExplorer = true;
  15.  
  16.  
  17. // Change this if you wish to exclude Fleets whose names contain the excludeString from being auto Selected as next explorer.
  18. unsafeWindow.useExcludeString = false;
  19. // Change this to what you would like to put into a fleet's name in order to exclude it from being auto selected.
  20. unsafeWindow.excludeString = "#NotAuto#";
  21.  
  22.  
  23. // Change this if you wish to auto Select Fleets as next explorer ONLY if their names contain the includeString.
  24. unsafeWindow.useIncludeString = false;
  25. // Change this to what you would like to put into a fleet's name in order to include it into being auto selected.
  26. unsafeWindow.includeString = "#Auto#";
  27.  
  28.  
  29.  
  30.  
  31. //Script
  32.  
  33. $(window).load(function(){
  34.  
  35.  
  36.  
  37. var classificationNode = document.getElementById('fleetClass');
  38. var isExplorer = document.evaluate("//text()[contains(.,'Explorer') or contains(.,'Sentry') or contains(.,'Probe Rush')]", classificationNode, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
  39.  
  40.  
  41. if (isExplorer){
  42.  
  43. var info = document.getElementById('navData').getElementsByTagName('div')[4];
  44. var infoSpan = info.getElementsByTagName('span')[0];
  45.  
  46. // not containing world in the span.
  47. var isAtSystemEntrance = ! (document.evaluate("//text()[contains(.,'World:')]", infoSpan, null, XPathResult.BOOLEAN_TYPE, null).booleanValue);
  48.  
  49.  
  50.  
  51. //alert("Is explorer = " + isExplorer);
  52. //alert("Is at system Entrance = " + isAtSystemEntrance);
  53. var currentPlanet = info.getElementsByTagName('a')[0].innerHTML;
  54.  
  55.  
  56. //alert(currentPlanet);
  57.  
  58. var optionGroup = document.getElementById('target1').getElementsByTagName('optgroup')[0].getElementsByTagName('option');
  59.  
  60. var i = 0 , found = false, optionsLength = optionGroup.length;
  61. var nextPlanetOption, finishedSystem = false;
  62.  
  63.  
  64.  
  65. //if I am at system entrance
  66. if (isAtSystemEntrance){
  67. found = true;
  68. nextPlanetOption = optionGroup[0].value;
  69. }
  70.  
  71.  
  72. //if PlanetLess system
  73. if (optionsLength == 0 ) {
  74. found = true;
  75. finishedSystem = true;
  76. }
  77.  
  78.  
  79. // If I am at a planet, Find next planet through the local target option list
  80.  
  81. while ( (i < optionsLength) && (found == false) ) {
  82.  
  83. if (optionGroup[i].innerHTML == currentPlanet ){
  84. found = true;
  85.  
  86. if ( i == optionsLength -1 ){
  87. finishedSystem = true;
  88. } else {
  89. nextPlanetOption = optionGroup[i+1].value;
  90. }
  91. }
  92.  
  93. i++;
  94.  
  95. }
  96.  
  97.  
  98. // alert("finished system = " + finishedSystem);
  99. // alert("next planet = " + nextPlanetOption);
  100.  
  101.  
  102. // alert("Reached finished System");
  103.  
  104. if (finishedSystem) {
  105. // alert("Inside finished System");
  106. document.getElementById('missionData').innerHTML += '<input class = "greenbutton darkbutton" type="button" id="nextPlanetButton" value = "Done" onclick="openStarMap()" />';
  107. document.getElementById('nextPlanetButton').addEventListener('click', openStarMap, false);
  108. } else {
  109. // alert("Inside NOT finished System");
  110. document.getElementById('missionData').innerHTML += '<input class = "greenbutton darkbutton" type="button" id="nextPlanetButton" value = "Next Planet" onclick="selectNextPlanet()" />';
  111. document.getElementById('nextPlanetButton').addEventListener('click', selectNextPlanet, false);
  112.  
  113. }
  114.  
  115. }
  116.  
  117.  
  118.  
  119. function selectNextPlanet(){
  120. jQuery('#target1').val(nextPlanetOption).trigger ('change');
  121.  
  122. if (unsafeWindow.AutoLaunch){
  123. unsafeWindow.hasLaunched = false;
  124. window.setTimeout(launchFleet,100);
  125. }
  126.  
  127. }
  128.  
  129. function openStarMap(){
  130. var starMapLink;
  131. if (isAtSystemEntrance){
  132. starMapLink = document.getElementById('navData').getElementsByTagName('div')[10].getElementsByTagName('a')[0].href;
  133. } else {
  134. starMapLink = document.getElementById('navData').getElementsByTagName('div')[11].getElementsByTagName('a')[0].href;
  135. }
  136.  
  137. starMapLink = starMapLink.substring(19, starMapLink.length - 3 ); //Keep only the link, throw away the functions
  138.  
  139. // mapWin is war-facts.com function to open javascript map
  140. mapWin(starMapLink);
  141.  
  142. }
  143.  
  144.  
  145.  
  146. function launchFleet(){
  147. var launchButton = document.getElementById('mButton').getElementsByTagName('input')[0];
  148.  
  149. if (launchButton) { //So Button has been created
  150. getMission('launch'); //Launch Fleet
  151. unsafeWindow.hasLaunched = true;
  152.  
  153. autoSelectNextExplorer();
  154.  
  155. } else {
  156. window.setTimeout(launchFleet,100);
  157. }
  158.  
  159.  
  160.  
  161.  
  162. }
  163.  
  164.  
  165.  
  166.  
  167. function checkIfLaunched(){
  168. var abortButton = document.getElementById('mButton').children[0];
  169.  
  170. if ( (abortButton) && (abortButton.value == "Abort Mission") ) {
  171. autoSelectNextExplorer();
  172. }else {
  173. alert("Trying Again");
  174. window.setTimeout(checkIfLaunched,250);
  175. }
  176.  
  177. }
  178.  
  179.  
  180. function autoSelectNextExplorer(){
  181.  
  182. if (unsafeWindow.AutoSelectNextExplorer) {
  183.  
  184.  
  185. var explorerList = document.getElementById('fc_Explorer').children;
  186. var index = 0;
  187. var explorerListLength = explorerList.length;
  188.  
  189.  
  190. while (index < explorerListLength) {
  191.  
  192. if (explorerList[index].children[0].style.color == "rgb(242, 242, 242)") {
  193. var link = explorerList[index].children[0].href;
  194. var name = explorerList[index].children[0].innerHTML;
  195.  
  196. if (( ( !unsafeWindow.useIncludeString) || ( name.indexOf(unsafeWindow.includeString) > -1 ) ) //If not using include string or String is in name
  197. && ( ( !unsafeWindow.useExcludeString) || ( name.indexOf(unsafeWindow.excludeString) == -1 ) ) //If not using exclude string or String is NOT in name
  198. && ( link != window.location.href ) //Make sure we are not chosing ourselve as this fleet is still "white"
  199. ) {
  200. index = explorerListLength; //To make sure if load doesn't happen immediately it stops running through fleet list
  201. window.open(link, "_self");
  202. }
  203. }
  204.  
  205. index++;
  206. }
  207. }
  208. }
  209.  
  210.  
  211. });