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 5
  7. // @run-at document-end
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. //Configuration Options:
  12.  
  13. //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
  14. var AutoLaunch = true;
  15. var AutoSelectNextExplorer = true;
  16.  
  17.  
  18. // Change this if you wish to exclude Fleets whose names contain the excludeString from being auto Selected as next explorer.
  19. var useExcludeString = false;
  20. // Change this to what you would like to put into a fleet's name in order to exclude it from being auto selected.
  21. var excludeString = "#NotAuto#";
  22.  
  23.  
  24. // Change this if you wish to auto Select Fleets as next explorer ONLY if their names contain the includeString.
  25. var useIncludeString = false;
  26. // Change this to what you would like to put into a fleet's name in order to include it into being auto selected.
  27. var includeString = "#Auto#";
  28.  
  29.  
  30. //Script
  31.  
  32.  
  33. //$(window).load(function() {
  34.  
  35.  
  36. window.setTimeout(runWholeScript,100); //Added some extra delay cause sometimes script didn't have time to load correctly
  37.  
  38.  
  39. function runWholeScript(){
  40.  
  41. var classificationNode = document.getElementById('fleetClass');
  42. var isExplorer = document.evaluate("//text()[contains(.,'Explorer') or contains(.,'Sentry') or contains(.,'Probe Rush')]", classificationNode, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
  43.  
  44.  
  45. if (isExplorer){
  46.  
  47. var info = document.getElementById('navData').getElementsByTagName('div')[4];
  48. var infoSpan = info.getElementsByTagName('span')[0];
  49.  
  50. // not containing world in the span.
  51. var isAtSystemEntrance = ! (document.evaluate("//text()[contains(.,'World:')]", infoSpan, null, XPathResult.BOOLEAN_TYPE, null).booleanValue);
  52.  
  53.  
  54. //alert("Is explorer = " + isExplorer);
  55. //alert("Is at system Entrance = " + isAtSystemEntrance);
  56. var currentPlanet = info.getElementsByTagName('a')[0].innerHTML;
  57.  
  58.  
  59. //alert(currentPlanet);
  60. var optionGroup = document.getElementById('target1');
  61. optionGroup = optionGroup.getElementsByTagName('optgroup')[0];
  62. optionGroup = optionGroup.getElementsByTagName('option');
  63.  
  64. var i = 0 , found = false, optionsLength = optionGroup.length;
  65. var nextPlanetOption, finishedSystem = false;
  66.  
  67.  
  68.  
  69.  
  70. //if PlanetLess system
  71. if (optionsLength === 0 ) {
  72. // alert("Planetless System");
  73. found = true;
  74. finishedSystem = true;
  75. } else if (isAtSystemEntrance){ //if I am at system entrance
  76. // alert("At System Entrance");
  77. found = true;
  78. nextPlanetOption = optionGroup[0].value;
  79. }
  80.  
  81. // If I am at a planet, Find next planet through the local target option list
  82.  
  83. while ( (i < optionsLength) && (found == false) ) {
  84.  
  85. if (optionGroup[i].innerHTML == currentPlanet ){
  86. found = true;
  87.  
  88. if ( i == optionsLength -1 ){
  89. finishedSystem = true;
  90.  
  91. } else {
  92. nextPlanetOption = optionGroup[i+1].value;
  93. }
  94. }
  95.  
  96. i++;
  97.  
  98. }
  99.  
  100. // alert("finished system = " + finishedSystem);
  101. // alert("next planet = " + nextPlanetOption);
  102.  
  103.  
  104. // alert("Reached finished System");
  105.  
  106. if (finishedSystem) {
  107. // alert("Inside finished System");
  108. document.getElementById('missionData').innerHTML += '<input class = "greenbutton darkbutton" type="button" id="nextPlanetButton" value = "Done" onclick="openStarMap()" />';
  109. document.getElementById('nextPlanetButton').addEventListener('click', openStarMap, false);
  110. } else {
  111. // alert("Inside NOT finished System");
  112. document.getElementById('missionData').innerHTML += '<input class = "greenbutton darkbutton" type="button" id="nextPlanetButton" value = "Next Planet" onclick="selectNextPlanet()" />';
  113. document.getElementById('nextPlanetButton').addEventListener('click', selectNextPlanet, false);
  114.  
  115. }
  116.  
  117. }
  118.  
  119.  
  120. function selectNextPlanet(){
  121. jQuery('#target1').val(nextPlanetOption).trigger ('change');
  122.  
  123.  
  124.  
  125. if (AutoLaunch){
  126. window.setTimeout(launchFleet,100);
  127. }
  128.  
  129. }
  130.  
  131. function openStarMap(){
  132. var starMapLink;
  133. if (isAtSystemEntrance){
  134. starMapLink = document.getElementById('navData').getElementsByTagName('div')[10].getElementsByTagName('a')[0].href;
  135. } else {
  136. starMapLink = document.getElementById('navData').getElementsByTagName('div')[11].getElementsByTagName('a')[0].href;
  137. }
  138.  
  139. starMapLink = starMapLink.substring(19, starMapLink.length - 3 ); //Keep only the link, throw away the functions
  140.  
  141. // mapWin is war-facts.com function to open javascript map
  142. mapWin(starMapLink);
  143.  
  144. }
  145.  
  146.  
  147.  
  148. function launchFleet(){
  149. var launchButton = document.getElementById('mButton').getElementsByTagName('input')[0];
  150.  
  151. if (launchButton) { //So Button has been created
  152. getMission('launch'); //Launch Fleet
  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 (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 (( ( !useIncludeString) || ( name.indexOf(includeString) > -1 ) ) //If not using include string or String is in name
  197. && ( ( !useExcludeString) || ( name.indexOf(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.  
  212.  
  213. //});
  214.