Auto Select Next Explorer

Automatically Selects next Explorer When explorer is launched. For Warring Factions www.war-facts.com New Interface

  1. // ==UserScript==
  2. // @name Auto Select Next Explorer
  3. // @namespace https://greasyfork.org/en/users/10321-nikitas
  4. // @version 1
  5. // @description Automatically Selects next Explorer When explorer is launched. For Warring Factions www.war-facts.com New Interface
  6. // @author guardian
  7. // @match http://*.war-facts.com/fleet.php*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. //Replaces game's getMission function, so that if it is an explorer it autolaunches
  12. function newgetMission(){
  13.  
  14. //Configuration Options:
  15. // Change this if you wish to exclude Fleets whose names contain the excludeString from being auto Selected as next explorer.
  16. var useExcludeString = false;
  17. // Change this to what you would like to put into a fleet's name in order to exclude it from being auto selected.
  18. var excludeString = "#NotAuto#";
  19.  
  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. //Script
  27.  
  28.  
  29.  
  30.  
  31. function autoSelectNextExplorer(){
  32.  
  33. var explorerList = document.getElementById('fc_Explorer').children;
  34. var index = 0;
  35. var explorerListLength = explorerList.length;
  36. while (index < explorerListLength) {
  37. // alert("Index = " +index);
  38.  
  39. if (explorerList[index].children[0].style.color == "rgb(242, 242, 242)") {
  40. var link = explorerList[index].children[0].href;
  41. var fleet_with_id = link.substr(link.indexOf("fleet="));
  42. var name = explorerList[index].children[0].innerHTML;
  43. var current_window = window.location.href;
  44. // alert("Fleet with name " + name +" and with id " + fleet_with_id);
  45. if (
  46. ( ( !useIncludeString) || ( name.indexOf(includeString) > -1 ) ) //If not using include string or String is in name
  47. && ( ( !useExcludeString) || ( name.indexOf(excludeString) == -1 ) ) //If not using exclude string or String is NOT in name
  48. && ( current_window.indexOf(fleet_with_id) == -1 )//Make sure we are not chosing ourselve as this fleet is still "white"
  49. )
  50. {
  51. index = explorerListLength; //To make sure if load doesn't happen immediately it stops running through fleet list
  52. window.open(link, "_self");
  53. }
  54. }
  55. index++;
  56. }
  57. }
  58.  
  59. // Replace the site's getMission function, so that when launch is pressed, it autoSelectsNextExplorer
  60. var oldgetMission = getMission;
  61.  
  62. window.getMission = function getMission(action, dType) {
  63. var executed = new oldgetMission(action, dType);
  64. if (action == 'launch'){
  65. var classificationNode = document.getElementById('fleetClass');
  66. var isExplorer = document.evaluate("//text()[contains(.,'Explorer') or contains(.,'Sentry') or contains(.,'Probe Rush')]", classificationNode, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
  67. window.setTimeout(autoSelectNextExplorer,250);
  68. }
  69. }
  70. }
  71.  
  72. // this is the only script injection technique I've found which works on Chrome with the above function
  73. var inject = document.createElement("script");
  74. inject.setAttribute("type", "text/javascript");
  75. inject.appendChild(document.createTextNode("(" + newgetMission + ")()"));
  76. document.body.appendChild(inject);
  77.  
  78.  
  79.  
  80.