// ==UserScript== // @name OGame Redesign: Easy Transport // @namespace RiV-easytransport // @description Provides links to easily transport the resources needed for a building/research // @version 1.1a // @include http://*.ogame.*/game/index.php?page=resources* // @include http://*.ogame.*/game/index.php?page=station* // @include http://*.ogame.*/game/index.php?page=research* // @include http://*.ogame.*/game/index.php?page=fleet* // ==/UserScript== (function() { var unsafe = window; try { unsafe = unsafeWindow } catch (e) { } if (!this.GM_getValue || (this.GM_getValue.toString && this.GM_getValue.toString().indexOf("not supported")>-1)) { this.GM_getValue=function (key,def) { return localStorage[key] || def; }; this.GM_setValue=function (key,value) { return localStorage[key]=value; }; this.GM_deleteValue=function (key) { return delete localStorage[key]; }; } function setValue(name, value) { GM_setValue(name + '|' + uni, JSON.stringify(value)); } function getValue(name, defaultValue) { var val = GM_getValue(name + '|' + uni); if(val == undefined) return defaultValue; return JSON.parse(val); } var page = document.URL; page = page.substring(page.indexOf('page=')+5, page.indexOf('&session')); var uni = window.location.host; uni = uni.split('.')[0]; var uniName = [ ["uni101", "andromeda"], ["uni102", "barym"], ["uni103", "capella"], ["uni104", "draco"], ["uni105", "electra"], ["uni106", "fornax"], ["uni107", "gemini"], ["uni108", "hydra"], ["uni109", "io"], ["uni110", "jupiter"], ["uni111", "kassiopeia"], ["uni112", "leo"], ["uni113", "mizar"], ["uni114", "nekkar"], ["uni115", "orion"], ["uni116", "pegasus"], ["uni117", "quantum"], ["uni118", "rigel"], ["uni119", "sirius"], ["uni120", "taurus"], ["uni121", "ursa"], ["uni122", "vega"], ["uni123", "wasat"], ["uni124", "xalynth"], ["uni125", "yakini"], ["uni126", "zagadra"] ]; for(var i = 0; i < uniName.length; i++) { uni = uni.replace(uniName[i][1], uniName[i][0]); } var domain = window.location.host; domain = domain.split('.')[2]; uni = uni + domain; var coords = getElementsByClass('active'); if(!coords[0]) coords = getElementsByClass('planetlink'); coords = coords[0].title; coords = coords.substring(coords.indexOf('[')+1, coords.indexOf(']')); var moon = false; if(unsafe.resourceTickerMetal ["production"] == 0) moon = true; var uniSpeed = 1; var Sp; switch (uni) { case "uni50de" : case "uni60de" : case "uni70de" : case "uni106de" : case "uni111de" : case "uni30org" : case "uni40org" : case "uni42org" : case "uni110org" : Sp = 2; break; case "uni105de" : case "uni105org" : Sp = 4; break; case "uni35org" : Sp = 5; break; default: Sp = 1; } /* User variables, change if you wish */ // change Speed manually if your uni isn't listed or add your Universe to the list uniSpeed = Sp; // whether to use Small Cargos or not var useSmallCargos = false; // speed factor of the flight; 1 = 100%, 0.5 = 50% etc. var speedFactor = 1; /* End of user variables */ var transportBuild = getValue('transportBuild'); var transportLevel = getValue('transportLevel'); var transportMet = getValue('transportMet'); var transportCrys = getValue('transportCrys'); var transportDeut = getValue('transportDeut'); var transportGala = getValue('transportGala'); var transportSolSys = getValue('transportSolSys'); var transportPos = getValue('transportPos'); var transportMoon = getValue('transportMoon', false); var CombDrive = getValue('CombDrive', 0); var ImpDrive = getValue('ImpDrive', 0); var easyTransport = getValue('easyTransport', false); if(domain == 'de') { langTransport = 'Transport'; langAll = 'alle'; langMissing = 'fehlende'; langDelete = 'löschen'; langTransportLink = transportBuild + ' ' + transportLevel + ' nach [' + transportGala + ':' + transportSolSys + ':' + transportPos + ']'; langNotEnoughRes = 'Nicht genügend Rohstoffe!'; langNotEnoughShips = 'Nicht genügend Schiffe!'; langCancel = 'Abbrechen'; langMoon = 'Mond'; } else { langTransport = 'Transport'; langAll = 'all'; langMissing = 'missing'; langDelete = 'delete'; langTransportLink = transportBuild + ' ' + transportLevel + ' to [' + transportGala + ':' + transportSolSys + ':' + transportPos + ']'; langNotEnoughRes = 'Not enough resources!'; langNotEnoughShips = 'Not enough ships!'; langCancel = 'Cancel'; langMoon = 'Moon'; } // get an element via its class name | thx @ marshen for the code function getElementsByClass (cName, domNode) { if (cName == undefined || cName.length == 0) return; if (domNode == undefined) domNode = document; if (domNode.getElementsByClassName) return domNode.getElementsByClassName(cName); // browser doesn't support getElementsByClassName cName = " " + cName + " "; // add spaces here so that we won't find class "a" in className == "abc" var elements = domNode.getElementsByTagName('*'); var res = new Array(); for (var i = 0; i < elements.length; i++) { var className = " " + elements[i].className + " "; if (className.indexOf(cName) > -1) { res.push(elements[i]); } } return res; } function removeSeparator(str) { if (!str) return null; return parseInt(str.replace(/\./g, '')); } function getBuildingInfo() { var res = new Array(); res[0] = document.getElementById('content').innerHTML; res[0] = res[0].substring(res[0].indexOf('

')+4, res[0].indexOf('

')); res[1] = getElementsByClass('level', document.getElementById('content'))[0].innerHTML; res[1] = parseInt(res[1].match(/\d+/)[0]) + 1; var costs = document.getElementById('costs'); costs = getElementsByClass('metal', costs); for(var i = 0; i < costs.length; i++) { var resType = costs[i].innerHTML; resType = resType.match(/ressourcen_(.+)\S+gif/); resType = RegExp.$1; var resValue = costs[i].title; resValue = resValue.substring(1, resValue.indexOf(' ')); resValue = removeSeparator(resValue); resValue = (resValue > 0) ? resValue : 0; if(resType == 'metall') res[2] = resValue; if(resType == 'kristal') res[3] = resValue; if(resType == 'deuterium') res[4] = resValue; } for(var i = 0; i < 3; i++) res[i+2] = (res[i+2] > 0) ? res[i+2] : 0; return res; } function getPlanetInfo(ress) { var res = document.getElementById(ress + '_box').title; res = res.split('
')[0]; res = res.replace('', ''); res = res.substring(res.lastIndexOf('>')+1); res = removeSeparator(res); return parseInt(res); } function getDistance(Gala, SolSys, Pos) { if (Gala == transportGala && SolSys == transportSolSys && Pos == transportPos) res = 5; else if (Gala == transportGala && SolSys == transportSolSys) res = Math.abs(Pos - transportPos) * 5 + 1000; else if (Gala == transportGala) res = Math.abs(SolSys - transportSolSys) * 95 + 2700; else res = Math.abs(Gala - transportGala) * 20000; return parseInt(res); } function getFlightTime(dist, velo) { var res = ((3500 / speedFactor) * Math.pow((dist * 10 / velo), 0.5) + 10) / uniSpeed; return parseInt(res); } function getShipInfo(info) { if(useSmallCargos) { if(info == 'id') res = '202'; if(info == 'velocity') { if(ImpDrive >= 5) res = 10000 + 10000 * 0.2 * ImpDrive; else res = 5000 + 5000 * 0.1 * CombDrive; } if(info == 'baseconsumption') { if(ImpDrive >= 5) res = 20; else res = 10; } if(info == 'capacity') res = 5000; } else { if(info == 'id') res = '203'; if(info == 'velocity') res = 7500 + 7500 * 0.1 * CombDrive; if(info == 'capacity') res = 25000; if(info == 'baseconsumption') res = 50; } return res; } function getConsumption(fTime, dist, velo, bCons) { var value = 35000 / (fTime * uniSpeed - 10) * Math.pow((dist * 10 / velo), 0.5); var res = bCons * dist / 35000 * Math.pow((value / 10 + 1), 2); return parseInt(res); } function getNeededShipCount() { var startGala = coords.split(':')[0]; var startSolSys = coords.split(':')[1]; var startPos = coords.split(':')[2]; var Velocity = getShipInfo('velocity'); var Distance = getDistance(startGala, startSolSys, startPos); var flightTime = getFlightTime(Distance, Velocity); var baseConsumption = getShipInfo('baseconsumption'); var Capacity = getShipInfo('capacity'); var Consumption = getConsumption(flightTime, Distance, Velocity, baseConsumption); var res = Math.ceil((transportMet + transportCrys + transportDeut) / (Capacity - Consumption)); return parseInt(res); } function getShipCount() { var id = getShipInfo('id'); var res = document.getElementById('button' + id); res = res.innerHTML; res = res.substring(res.indexOf('(')+1, res.indexOf(')')); return removeSeparator(res); } function allResources() { var buildingInfo = getBuildingInfo(); transportBuild = buildingInfo[0]; transportLevel = buildingInfo[1]; transportMet = buildingInfo[2] ? buildingInfo[2] : 0; transportCrys = buildingInfo[3] ? buildingInfo[3] : 0; transportDeut = buildingInfo[4] ? buildingInfo[4] : 0; transportGala = coords.split(':')[0]; transportSolSys = coords.split(':')[1]; transportPos = coords.split(':')[2]; setValue('transportBuild', transportBuild); setValue('transportLevel', transportLevel); setValue('transportMet', transportMet); setValue('transportCrys', transportCrys); setValue('transportDeut', transportDeut); setValue('transportGala', transportGala); setValue('transportSolSys', transportSolSys); setValue('transportPos', transportPos); setValue('transportMoon', moon); document.getElementById('all_res').style.color = '#ff0000'; document.getElementById('missing_res').style.color = ''; } function missingResources() { var Metal = getPlanetInfo('metal'); var Crystal = getPlanetInfo('crystal'); var Deut = getPlanetInfo('deuterium'); var buildingInfo = getBuildingInfo(); transportBuild = buildingInfo[0]; transportLevel = buildingInfo[1]; transportMet = ((buildingInfo[2]-Metal) > 0) ? (buildingInfo[2]-Metal) : 0; transportCrys = ((buildingInfo[3]-Crystal) > 0) ? (buildingInfo[3]-Crystal) : 0; transportDeut = ((buildingInfo[4]-Deut) > 0) ? (buildingInfo[4]-Deut) : 0; transportGala = coords.split(':')[0]; transportSolSys = coords.split(':')[1]; transportPos = coords.split(':')[2]; setValue('transportBuild', transportBuild); setValue('transportLevel', transportLevel); setValue('transportMet', transportMet); setValue('transportCrys', transportCrys); setValue('transportDeut', transportDeut); setValue('transportGala', transportGala); setValue('transportSolSys', transportSolSys); setValue('transportPos', transportPos); setValue('transportMoon', moon); document.getElementById('all_res').style.color = ''; document.getElementById('missing_res').style.color = '#ff0000'; } function insertText(e) { if(e.target.id != 'content') return; var costs = document.getElementById('costs'); costs.innerHTML += '' + langTransport + ':
' + langAll + '   ' + langMissing + ''; document.getElementById('all_res').addEventListener('click', allResources, false); document.getElementById('missing_res').addEventListener('click', missingResources, false); } function deleteTransport() { setValue('transportBuild', ''); setValue('transportLevel', ''); setValue('transportMet', ''); setValue('transportCrys', ''); setValue('transportDeut', ''); setValue('transportGala', ''); setValue('transportSolSys', ''); setValue('transportPos', ''); setValue('easyTransport', false); if(page == 'fleet1') document.getElementById('transportlink').innerHTML = ''; } // thanks to Antigame author Tarja for code function runScript(code) { if (!code || code=="") return; var script = document.createElement('script'); script.setAttribute('type','text/javascript'); script.innerHTML = code; document.body.appendChild(script); setTimeout(function(){script.parentNode.removeChild(script)}, 0); } // thanks to Antigame author Tarja for code function trigger(id, event) { var evt = document.createEvent("HTMLEvents"); evt.initEvent(event, true, false); if (evt) document.getElementById(id).dispatchEvent(evt); } function fillInShips() { var id = getShipInfo('id'); var Count = getNeededShipCount(); var easyTransport = getValue('easyTransport', false); if(!easyTransport) { setValue('easyTransport', true); document.getElementById('easytransport').innerHTML = langCancel; document.getElementById('ship_' + id).value = Count; document.getElementById('easytransport').addEventListener('click', fillInShips, false); } else { setValue('easyTransport', false); document.getElementById('ship_' + id).value = ''; document.getElementById('easytransport').innerHTML = langTransportLink; document.getElementById('easytransport').addEventListener('click', fillInShips, false); } trigger('ship_' + id, 'change'); } function showLink() { if(!getElementsByClass('allornonewrap')[0]) return; var allOrNoneWrap = getElementsByClass('allornonewrap')[0]; var transportLinkCont = document.createElement('div'); transportLinkCont.style.marginLeft = '120px'; var strMoon = ''; if(transportMoon) strMoon = ' ' + langMoon; var transportLink = document.createElement('span'); transportLink.id = 'transportlink'; transportLink.innerHTML = '' + langTransportLink + strMoon + ' (' + langDelete + ')'; var Metal = getPlanetInfo('metal'); var Crystal = getPlanetInfo('crystal'); var Deut = getPlanetInfo('deuterium'); transportLinkCont.appendChild(transportLink); allOrNoneWrap.insertBefore(transportLinkCont, getElementsByClass('secondcol')[0].nextSibling); var blockLink = false; if(transportMet > Metal || transportCrys > Crystal || transportDeut > Deut) { var Link = document.getElementById('easytransport'); Link.style.color = '#ff0000'; Link.title = langNotEnoughRes; blockLink = true; } if(getNeededShipCount() > getShipCount()) { var Link = document.getElementById('easytransport'); Link.style.color = '#ff0000'; Link.title = langNotEnoughShips; blockLink = true; } document.getElementById('delete_transport').addEventListener('click', deleteTransport, false); if(!blockLink) document.getElementById('easytransport').addEventListener('click', fillInShips, false); } if(page == 'resources' || page == 'station' || page == 'research') document.getElementById('planet').addEventListener('DOMNodeInserted', insertText, false); if(page == 'fleet1') { setValue('easyTransport', false); if(transportBuild) { showLink(); } } if(page == 'fleet2') if(easyTransport) { document.getElementById('galaxy').value = transportGala; document.getElementById('system').value = transportSolSys; document.getElementById('position').value = transportPos; if(transportMoon) trigger('mbutton', 'click'); else trigger('pbutton', 'click'); trigger('galaxy', 'change'); } if(page == 'fleet3' && easyTransport) { document.getElementById('metal').value = transportMet; document.getElementById('crystal').value = transportCrys; document.getElementById('deuterium').value = transportDeut; trigger('missionButton3', 'click'); runScript('setTimeout(function(){checkRes();updateVariables();},0)'); document.getElementById('start').addEventListener('click', deleteTransport, false); } if(page == 'research') { var CombDrive = document.getElementById('inhalt').innerHTML.split('details115')[1]; CombDrive = CombDrive.match(/\d+/)[0]; setValue('CombDrive', CombDrive); var ImpDrive = document.getElementById('inhalt').innerHTML.split('details117')[1]; ImpDrive = ImpDrive.match(/\d+/)[0]; setValue('ImpDrive', ImpDrive); } }) ()