Explore Script

Warring Factions Explore Script

当前为 2016-09-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Explore Script
  3. // @version 0.4
  4. // @description Warring Factions Explore Script
  5. // @author Kevin Schlosser
  6. // @match http://*.war-facts.com/fleet.php*
  7. // @match http://*.war-facts.com/fleet/*
  8. // @require https://code.jquery.com/jquery-2.1.4.min.js
  9. // @grant none
  10. // @namespace https://gf.qytechs.cn/users/14655
  11. // ==/UserScript==
  12.  
  13. //Configuration Options:
  14. // Change this if you wish to exclude Fleets whose names contain the excludeString from being auto Selected as next explorer.
  15. var useExcludeString = false;
  16. // Change this to what you would like to put into a fleet's name in order to exclude it from being auto selected.
  17. var excludeString = "#NotAuto#";
  18. // How many milliseconds to wait between requests
  19. var timeout = 500;
  20.  
  21. // Change this if you wish to auto Select Fleets as next explorer ONLY if their names contain the includeString.
  22. var useIncludeString = false;
  23. // Change this to what you would like to put into a fleet's name in order to include it into being auto selected.
  24. var includeString = "#Auto#";
  25.  
  26. var explorerRegex = /Explorer/g;
  27. var isExplorer = explorerRegex.test(document.getElementById('fleetClass').innerText);
  28.  
  29. var base = window.location.href;
  30. var fleetIdRegex = /fleet.php.*fleet=(\d+)|fleet\/(\d+)/g;
  31. var match = fleetIdRegex.exec(base);
  32.  
  33. var fleetNumber = match[1] === undefined ? match[2] : match[1];
  34. var xmlhttp = new XMLHttpRequest();
  35. var perimeterScan, hasWormhole, hasColony;
  36. xmlhttp.onreadystatechange=function()
  37. {
  38. if (xmlhttp.readyState==4 && xmlhttp.status==200)
  39. {
  40. perimeterScanHtml = xmlhttp.responseText;
  41. var dom = document.createElement('html');
  42. dom.innerHtml = perimeterScan;
  43. dom.getElementsByTagName('table');
  44.  
  45. var el = $( '<div></div>' );
  46. el.html(perimeterScanHtml);
  47. var perimiterScan = $('table', el)[1];
  48. document.getElementById('missionData').appendChild(perimiterScan);
  49. hasWormhole = checkWH(perimiterScan.rows);
  50. hasColony = checkColony();
  51. if (!hasWormhole && !hasColony) {
  52. window.setTimeout(main,timeout);
  53. }
  54. }
  55. };
  56. if (isExplorer) {
  57. xmlhttp.open("GET", 'http://www.war-facts.com/extras/scan.php?fleet='+fleetNumber, true);
  58. xmlhttp.send();
  59. }
  60.  
  61. function main() {
  62. if (isExplorer) {
  63. var info = document.getElementById('navData').getElementsByTagName('div')[4];
  64. var infoSpan = info.getElementsByTagName('span')[0];
  65. // not containing world in the span.
  66. var isAtSystemEntrance = ! (document.evaluate("//text()[contains(.,'World:')]", infoSpan, null, XPathResult.BOOLEAN_TYPE, null).booleanValue);
  67.  
  68. //alert("Is explorer = " + isExplorer);
  69. //alert("Is at system Entrance = " + isAtSystemEntrance);
  70. var currentPlanet = info.getElementsByTagName('a')[0].innerHTML;
  71.  
  72. //alert(currentPlanet);
  73. var optionGroup = document.getElementById('target1');
  74. if (optionGroup === null) {
  75. window.setTimeout(main,timeout);
  76. return;
  77. }
  78. optionGroup = optionGroup.getElementsByTagName('optgroup')[0];
  79. optionGroup = optionGroup.getElementsByTagName('option');
  80.  
  81. var i = 0 , found = false, optionsLength = optionGroup.length;
  82. var nextPlanetOption, finishedSystem = false;
  83.  
  84. //if PlanetLess system
  85. if (optionsLength === 0 ) {
  86. // alert("Planetless System");
  87. found = true;
  88. finishedSystem = true;
  89. } else if (isAtSystemEntrance){ //if I am at system entrance
  90. // alert("At System Entrance");
  91. found = true;
  92. nextPlanetOption = optionGroup[0].value;
  93. }
  94.  
  95. // If I am at a planet, Find next planet through the local target option list
  96.  
  97. while ( (i < optionsLength) && (found === false) ) {
  98.  
  99. if (optionGroup[i].innerHTML == currentPlanet ){
  100. found = true;
  101.  
  102. if ( i == optionsLength -1 ){
  103. finishedSystem = true;
  104.  
  105. } else {
  106. nextPlanetOption = optionGroup[i+1].value;
  107. }
  108. }
  109. i++;
  110. }
  111.  
  112. if (finishedSystem) {
  113. // alert("Inside finished System");
  114. document.getElementById('missionData').innerHTML += '<input class = "greenbutton darkbutton" type="button" id="nextPlanetButton" value = "Done" />';
  115. document.getElementById('nextPlanetButton').addEventListener('click', openStarMap, false);
  116. } else {
  117. // alert("Inside NOT finished System");
  118. document.getElementById('missionData').innerHTML += '<input class = "greenbutton darkbutton" type="button" id="nextPlanetButton" value = "Next Planet" />';
  119. document.getElementById('nextPlanetButton').addEventListener('click', function() {
  120. jQuery('#target1').val(nextPlanetOption).trigger ('change');
  121. //window.setTimeout(launchFleet,timeout);
  122. }, false);
  123. selectNextPlanet(nextPlanetOption);
  124. //launchFleet();
  125. //autoSelectNextExplorer();
  126.  
  127. }
  128.  
  129.  
  130. }
  131. }
  132.  
  133. var nextPlanetOption;
  134.  
  135. function checkWH(rows){
  136. for (var x = 1; x < rows.length; x++) {
  137. var cells = rows[x].cells;
  138. for (var y = 0; y < cells.length; y++) {
  139. if (cells[y].innerText.indexOf('Wormhole!') != -1) {
  140. return true;
  141. }
  142. }
  143. }
  144. return false;
  145. }
  146.  
  147. function checkColony(){
  148. var links = $('a', document.getElementById('navData'));
  149. for (var x = 0; x < links.length; x++) {
  150. if (links[x].innerText.indexOf('(view colonies)') != -1) {
  151. return true;
  152. }
  153. }
  154. return false;
  155. }
  156.  
  157. function launchFleet() {
  158. getMission('launch'); //Launch Fleet
  159. window.setTimeout(autoSelectNextExplorer, 100);
  160. }
  161.  
  162. function openStarMap(){
  163. var info = document.getElementById('navData').getElementsByTagName('div')[4];
  164. var infoSpan = info.getElementsByTagName('span')[0];
  165. //var isAtSystemEntrance = ! (document.evaluate("//text()[contains(.,'World:')]", infoSpan, null, XPathResult.BOOLEAN_TYPE, null).booleanValue);
  166.  
  167. var links = document.getElementById('navData').getElementsByTagName('a');
  168. var starMapTgt;
  169. var globalRegex = /\d+, \d+, \d+ global/g;
  170. for(var x = 0; x < links.length; x++) {
  171. var text = links[x].innerText;
  172. if (globalRegex.exec(text)) {
  173. starMapTgt = links[x].href;
  174. break;
  175. }
  176. }
  177.  
  178. starMapTgt = starMapTgt.substring(19, starMapTgt.length - 3 ); //Keep only the link, throw away the functions
  179. // mapWin is war-facts.com function to open javascript map
  180. mapWin(starMapTgt);
  181. }
  182.  
  183. function selectNextPlanet(nextPlanetOption){
  184. jQuery('#target1').val(nextPlanetOption).trigger ('change');
  185. window.setTimeout(launchFleet,timeout);
  186. }
  187.  
  188. function autoSelectNextExplorer(){
  189.  
  190. var explorerList = document.getElementById('fc_Explorer').children;
  191. var index = 0;
  192. var explorerListLength = explorerList.length;
  193.  
  194. while (index < explorerListLength) {
  195. // alert("Index = " +index);
  196. if (explorerList[index].children[0].style.color == "rgb(204, 204, 204)") {
  197.  
  198. var link = explorerList[index].children[0].href;
  199. var fleet_with_id = link.substr(link.indexOf("fleet="));
  200. var name = explorerList[index].children[0].innerHTML;
  201. var current_window = window.location.href;
  202. // alert("Fleet with name " + name +" and with id " + fleet_with_id);
  203.  
  204. if (
  205. ( ( !useIncludeString) || ( name.indexOf(includeString) > -1 ) ) //If not using include string or String is in name
  206. && ( ( !useExcludeString) || ( name.indexOf(excludeString) == -1 ) ) //If not using exclude string or String is NOT in name
  207. && ( current_window.indexOf(fleet_with_id) == -1 )//Make sure we are not chosing ourselve as this fleet is still "white"
  208. )
  209. {
  210.  
  211. index = explorerListLength; //To make sure if load doesn't happen immediately it stops running through fleet list
  212. window.open(link, "_self");
  213. }
  214. }
  215. index++;
  216. }
  217. }
  218.  
  219. // Replace the site's getMission function, so that when launch is pressed, it autoSelectsNextExplorer
  220. var oldgetMission = window.getMission;
  221.  
  222. window.getMission = function getMission(action, dType) {
  223. var executed = new oldgetMission(action, dType);
  224. if (action == 'launch'){
  225. var classificationNode = document.getElementById('fleetClass');
  226. var isExplorer = document.evaluate("//text()[contains(.,'Explorer') or contains(.,'Sentry') or contains(.,'Probe Rush')]", classificationNode, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
  227. window.setTimeout(autoSelectNextExplorer,timeout);
  228. }
  229.  
  230. };

QingJ © 2025

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