FANDOM


//
(function() {
	var ui = document.createElement('div');
	ui.innerHTML = '<div id="hax_inputs"><label for="planet">Planet:</label> <select id="planet"></select> <label for="repeat">Action:</label> <select id="repeat" onkeyup="if(event.keyCode == 13) {document.getElementById(\'runhax\').onclick();}"><optgroup label="Run mission"><option>Raid Unguarded Ore</option><option>Raid Unguarded Crystal</option><option>Raid Abandoned Hydro</option><option>Raid an Ore Mine</option><option>Raid a Crystal Mine</option><option>Raid a Passing Atlas Class</option><option>Destroy Artemis</option><option>Harvest Debris Field</option><option>Raid Mining Asteroid</option><option disabled="disabled">Raid an Enemy Base</option><option disabled="disabled">Destroy Enemy Defenses</option><option disabled="disabled">Defeat Invaders</option><option disabled="disabled">Stop Hades Fleet</option></optgroup><optgroup label="Run daily"><option>Haul Cargo</option><option>Recon Enemy Territory</option><option>Escort Ship</option><option disabled="disabled">Slip Through Dragnet</option><option disabled="disabled">Answer Distress Call</option><option disabled="disabled">Escort Diplomats</option><option disabled="disabled">Plunder Distant Base</option></optgroup><optgroup label="Build building"><option>Ore Mine</option><option>Crystal Mine</option><option>Hydrogen Refinery</option><option>Solar Array</option><option>Nuclear Power Plant</option><option>Shipyard</option><option>Capitol</option><option>Research Lab</option><option>Missile Battery</option><option disabled="disabled">Foundry</option><option>Ore Warehouse</option><option>Crystal Warehouse</option><option>Hydrogen Storage</option><option disabled="disabled">Lunar Base</option><option disabled="disabled">Oracle</option><option disabled="disabled">Warp Gate</option></optgroup><optgroup label="Research"><option>Energy Tech</option><option>Laser Tech</option><option>Particle Tech</option><option disabled="disabled">Plasma Tech</option><option>Expedition Tech</option><option>FTL Tech</option><option>AI Tech</option><option>Espionage Tech</option><option disabled="disabled">ARC Net</option><option>Weapons Tech</option><option>Armor Tech</option><option>Shield Tech</option><option>Jet Drive</option><option>Pulse Drive</option><option>Warp Drive</option></optgroup><optgroup label="Build ship"><option>Helios Solar Satelite</option><option>Hermes Probe</option><option>Atlas Cargo</option><option>Hercules Cargo</option><option>Charon Transport</option><option>Dionysus Recycler</option><option>Gaia Colony Ship</option><option>Artemis Fighter</option><option>Apollo Fighter</option><option>Poseidon Cruiser</option><option disabled="disabled">Athena Battleship</option><option disabled="disabled">Ares Bomber</option><option disabled="disabled">Hades Battleship</option><option disabled="disabled">Prometheus Destroyer</option><option disabled="disabled">Zeus</option><option disabled="disabled">Titan Attack Platform</option></optgroup><optgroup label="Build defense"><option>Missile Battery</option><option>Laser Cannon</option><option>Pulse Cannon</option><option>Particle Cannon</option><option disabled="disabled">Gauss Cannon</option><option disabled="disabled">Plasma Cannon</option><option>Decoy</option><option>Large Decoy</option><option>Anti-Ballistic Missile</option><option disabled="disabled">Interplanetary Ballistic Missile</option></optgroup><optgroup label="Build droid"><option>Mine Droid</option><option>Crew Droid</option><option>Build Droid</option><option>Lab Droid</option></optgroup></select> <label for="quant" title="Number of missions executed at once. Specify 0 for max">Quantity:</label> <input id="quant" title="Number of missions executed at once. Specify 0 for max" type="text" onkeyup="if(event.keyCode == 13) {document.getElementById(\'runhax\').onclick();}" style="width:18px;"> <input id="runhax" type="submit" value=" Run " onclick="task(document.getElementById(\'repeat\').options[document.getElementById(\'repeat\').selectedIndex].innerHTML, document.getElementById(\'quant\').value); document.getElementById(\'quant\').value = \'\';"></div><div id="hax_tasks" style="margin-top:7px;"></div></div>';
	ui.id = 'hax';
	ui.style.margin = '1px 5px 0';
	document.getElementById('content').parentNode.insertBefore(ui, document.getElementById('content'));
	window.hax = {};
	hax.repeats = {};
	hax.timerVal = 0;
	var fleetstr = document.getElementById('fleets_used').textContent;
	hax.fleetsUsed = fleetstr.substring(0, fleetstr.indexOf('/'));
	hax.fleetsMax = fleetstr.substring(fleetstr.indexOf('/') + 1, fleetstr.indexOf(' ', fleetstr.indexOf('/')));
	hax.planets = {};
	var list = document.getElementById('user_planets').getElementsByTagName('div');
	for(var i in list) {
		if(list[i].className == 'planet' && list[i].parentNode.className != 'empty colony') {
			var link = list[i].getElementsByTagName('a')[0].href
			hax.planets[list[i].getElementsByTagName('div')[2].innerHTML] = link.substring(link.indexOf('=') + 1, link.indexOf('&'));
			document.getElementById('planet').innerHTML += '<option>' + list[i].getElementsByTagName('div')[2].innerHTML + '</option>';
		}
	}
})();
 
function timer() {
	hax.timerVal++;
	var list = document.getElementById('hax_tasks').getElementsByTagName('span');
	for(var i = 0; i < list.length; i++) {
		if(list[i].className == 'hax_time') {
			list[i].getElementsByTagName('span')[1].innerHTML = ((list[i].getElementsByTagName('span')[1].innerHTML * 1) - 1);
			if(list[i].getElementsByTagName('span')[1].innerHTML == '-1') {
				list[i].getElementsByTagName('span')[1].innerHTML = '59';
				list[i].getElementsByTagName('span')[0].innerHTML = (list[i].getElementsByTagName('span')[0].innerHTML * 1) - 1;
			}
			if(list[i].getElementsByTagName('span')[1].innerHTML * 1 < 10) {list[i].getElementsByTagName('span')[1].innerHTML = '0' + list[i].getElementsByTagName('span')[1].innerHTML;}
		}
	}
	if(hax.repeats[hax.timerVal]) {
		document.getElementById('hax_tasks').removeChild(document.getElementById('hax_task_' + hax.timerVal));
		eval(hax.repeats[hax.timerVal]);
		delete hax.repeats[hax.timerVal];
	}
	if(hax.timerVal % 5 == 0) {
		for(var i in hax.repeats) {
			if((i * 1) < hax.timerVal) {
				if(document.getElementById('hax_task_' + i)) {
					document.getElementById('hax_tasks').removeChild(document.getElementById('hax_task_' + i));
					eval(hax.repeats[i]);
				}
				delete hax.repeats[i];
			}
		}
	}
}
setInterval(timer, 1000);
 
function idOf(lookup) {
	switch(lookup.toLowerCase()) {
		case 'raid unguarded ore': return '1422628013';
		case 'raid unguarded crystal': return '1607853605';
		case 'raid abandoned hydro': return '1773794702';
		case 'raid an ore mine': return '1773794700';
		case 'raid a crystal mine': return '1231520105';
		case 'raid a passing atlas class': return '595845219';
		case 'destroy artemis': return '1773794698';
		case 'harvest debris field': return '1773794706';
		case 'raid mining asteroid': return '540485008';
		case 'haul cargo': return '1773794710';
		case 'recon enemy territory': return '1773794712';
		case 'escort ship': return '1773794714';
		case 'ore mine': return '3673923';
		case 'crystal mine': return '3673925';
		case 'hydrogen refinery': return '3673921';
		case 'solar array': return '3673927';
		case 'nuclear power plant': return '3673929';
		case 'shipyard': return '3673901';
		case 'capitol': return '3673903';
		case 'research lab': return '3673905';
		case 'missile silo': return '3673909';
		case 'factory': return '3673911';
		case 'ore warehouse': return '3673913';
		case 'crystal warehouse': return '3673915';
		case 'hydrogen storage': return '3673917';
		case 'laser tech': return '3673943';
		case 'armor tech': return '3673949';
		case 'weapons tech': return '3673937';
		case 'shield tech': return '3673945';
		case 'particle tech': return '3673953';
		case 'jet drive': return '3673955';
		case 'ai tech': return '3673933';
		case 'energy tech': return '3673931';
		case 'espionage tech': return '3673951';
		case 'pulse drive': return '3673941';
		case 'ftl tech': return '3673939';
		case 'expedition tech': return '3673957';
		case 'warp drive': return '3673947';
		case 'hermes probe': return '950199677';
		case 'helios solar satelite': return '1520091969';
		case 'artemis fighter': return '82638594';
		case 'atlas cargo': return '676893046';
		case 'apollo fighter': return '11551983';
		case 'charon transport': return '2073344048';
		case 'hercules cargo': return '1168728674';
		case 'dionysus recycler': return '960214949';
		case 'poseidon cruiser': return '1217299082';
		case 'gaia colony ship': return '796740346';
		case 'missile battery': return '1979549177';
		case 'laser cannon': return '261457244';
		case 'pulse cannon': return '1684335457';
		case 'particle cannon': return '551348363';
		case 'anti-ballistic missile': return '1976678024';
		case 'decoy': return '1979549178';
		case 'large decoy': return '1979549180';
		case 'mine droid': return '1183579017';
		case 'crew droid': return '1543276070';
		case 'build droid': return '370524223';
		case 'lab droid': return '822174206';
	}
	return false;
}
 
function currentPlanet() {
	var params = window.location.href.split('?')[1].split('&');
	for(var i in params) {
		if(params[i].split('=')[0] == 'current_planet') {return params[i].split('=')[1];}
	}
}
 
function XHR() {
	var xhr = new XMLHttpRequest();
	xhr.setRequestHeader('Accept', 'text/javascript, text/html, application/xml, text/xml, */*');
	xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
	xhr.setRequestHeader('X-Prototype-Version', '1.7');
	return xhr;
}
 
function getHTML(callback) {
	var xhr = new XMLHttpRequest();
	xhr.open('GET', window.location.href, true);
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4 && xhr.status == 200) {
			var result = document.createElement('html');
			result.innerHTML = xhr.responseText.substring(xhr.response.indexOf('>', xhr.response.indexOf('<html')) + 1, xhr.response.lastIndexOf('</html>'));
			result.getElementById = function(id) {var els = this.getElementsByTagName('*'); for(var i in els) {if(els[i].id == id) {return els[i];}}}
 
			if(typeof callback == 'function') {callback(result);}
			else if(typeof callback == 'array') {
				for(var i in callback) {
					if(typeof callback[i] == 'string') {document.getElementById(callback[i]).innerHTML = result.getElementById(callback[i]).innerHTML;}
					if(typeof callback[i] == 'function') {callback[i](result);}
				}
			}
		}
	}
	xhr.send();
}
 
function task(type, name, quant) {
	if(!idOf(name)) {alert('Error: Unable to locate id for selected task'); return;}
	switch(type) {
		case 'mission':
			switch(name.toLowerCase()) {
				case 'raid unguarded ore': var mins = 2.35; break;
				case 'raid unguarded crystal': var mins = 2.7; break;
				case 'raid abandoned hydro': var mins = 3.1; break;
				case 'raid an ore mine': var mins = 3.6; break;
				case 'raid a crystal mine': var mins = 4.4; break;
				case 'raid a passing atlas class': var mins = 6.3; break;
				case 'destroy artemis': var mins = 7.3; break;
				case 'harvest debris field': var mins = 30.3; break;
				case 'raid mining asteroid': var mins = 10.3; break;
				case 'raid an enemy base': var mins = 15.3; break;
				case 'destroy enemy defenses': var mins = 25.3; break;
				case 'defeat invaders': var mins = 30.3; break;
				case 'stop hades fleet': var mins = 33.3; break;
			}
			if(quant == undefined) {quant = 1;}
			if(quant != 0) {var num = quant;}
			else {var num = fleetsMax - fleetsUsed;}
			if(fleetsUsed + quant <= fleetsMax) {
				var xhr = XHR();
				xhr.open('POST', 'http://stardriftempires.com/missions/start_mission/' + idOf(name) + '?batch_size_' + idOf(name) + '=' + num + '&current_planet=' + currentPlanet() + '&ship_quantities=default', true);
				xhr.onreadystatechange = function() {
					if(xhr.readyState == 4 && xhr.status == 200) {	
						getHTML(['content', 'user_stats', 'nav_bar', function(result) {
							var fleetstr = result.getElementById('fleets_used').textContent;
							hax.fleetsUsed = fleetstr.substring(0, fleetstr.indexOf('/'));
							hax.fleetsMax = fleetstr.substring(fleetstr.indexOf('/') + 1, fleetstr.indexOf(' ', fleetstr.indexOf('/')));
							var list = document.getElementById('user_planets').getElementsByTagName('div');
							document.getElementById('planet').innerHTML = '';
							for(var i in list) {
								if(list[i].className == 'planet' && list[i].parentNode.className != 'empty colony') {
									var link = list[i].getElementsByTagName('a')[0].href
									hax.planets[list[i].getElementsByTagName('div')[2].innerHTML] = link.substring(link.indexOf('=') + 1, link.indexOf('&'));
									document.getElementById('planet').innerHTML += '<option>' + list[i].getElementsByTagName('div')[2].innerHTML + '</option>';
								}
							}
						}]);
					}
				}
				xhr.send('');
			}
			break;
	}
	var rand = Math.random() * 12500 + 3000;
	var ref = (Math.floor((mins * 60 * 1000) + (rand - (rand % 1000)) - 5000)) / 1000;
	hax.repeats[hax.timerVal + ref] = 'task(\'' + type + '\', \'' + name + '\',' + quant + ')';
	var html = document.createElement('div');
	html.innerHTML = '<span style="color:red; font-family:monospace; cursor:pointer;" onclick="delete hax.repeats[' + ref + ']; this.parentNode.parentNode.removeChild(this.parentNode);">X</span> <span style="text-transform:capitalize;">' + name.toLowerCase() + '</span> <span class="quant">(' + ((quant == 0) ? 'max' : 'x' + quant) + ')</span> in <span class="hax_time"><span class="hax_time_minutes">' + Math.floor(mins) + '</span>:<span class="hax_time_seconds">' + ((ref % 60 < 10) ? '0' : '') + ref % 60 + '</span></span>';
	html.id = 'hax_task_' + ((hax.timerVal * 1) + (ref * 1));
	document.getElementById('hax_tasks').appendChild(html);
}
 
String.prototype.removeTrailing = function(char) {
	var str = this;
	var cont = true;
	while(cont) {
		cont = false;
		for(var i = 0; i < char.length; i++) {
			if(str.charAt(0) == char.charAt(i)) {str = str.substring(1, str.length); cont = true; break;}
		}
	}
	cont = true;
	while(cont) {
		cont = false;
		for(var i = 0; i < char.length; i++) {
			if(str.charAt(str.length - 1) == char.charAt(i)) {str = str.substring(0, str.length - 1); cont = true; break;}
		}
	}
	return str;
}
 
//

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.