Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Ogame Helper
- // @description none
- // @version 1
- // @grant none
- // @include http://*/game/index.php?page=*
- // @include https://*/game/index.php?page=*
- // ==/UserScript==
- (function () {
- function _getMeta(metaName) {
- const metas = document.getElementsByTagName('meta');
- for (let i = 0; i < metas.length; i++) {
- if (metas[i].getAttribute('name') === metaName) {
- return metas[i].getAttribute('content');
- }
- }
- return '';
- }
- function _setCookie(cname, cvalue, exdays) {
- /*var d = new Date();
- d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
- var expires = "expires="+d.toUTCString();*/
- var d1 = new Date();
- d1.setHours(d1.getHours() + (23 - d1.getHours()));
- d1.setMinutes(d1.getMinutes() + (59 - d1.getMinutes()));
- d1.setSeconds(d1.getSeconds() + (59 - d1.getSeconds()));
- var expires = "expires="+d1.toUTCString();
- document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
- }
- function _getCookie(cname) {
- var name = cname + "=";
- var ca = document.cookie.split(';');
- for(var i = 0; i < ca.length; i++) {
- var c = ca[i];
- while (c.charAt(0) == ' ') {
- c = c.substring(1);
- }
- if (c.indexOf(name) == 0) {
- return c.substring(name.length, c.length);
- }
- }
- return "";
- }
- function _formatNumber(amount, decimalCount = 2, decimal = ".", thousands = ",") {
- try {
- decimalCount = Math.abs(decimalCount);
- decimalCount = isNaN(decimalCount) ? 2 : decimalCount;
- const negativeSign = amount < 0 ? "-" : "";
- let i = parseInt(amount = Math.abs(Number(amount) || 0).toFixed(decimalCount)).toString();
- let j = (i.length > 3) ? i.length % 3 : 0;
- return negativeSign + (j ? i.substr(0, j) + thousands : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands) + (decimalCount ? decimal + Math.abs(amount - i).toFixed(decimalCount).slice(2) : "");
- } catch (e) {
- console.log(e)
- }
- }
- function _removeNumberPoints(str){
- while(str.indexOf('.') != -1){
- str = str.replace('.', '');
- }
- return str;
- }
- function _showFlyingRes(oCell){
- var tbl = document.createElement('table');
- //tbl.setAttribute('width', '100%');
- tbl.setAttribute('cellspacing', '0px');
- tbl.setAttribute('cellpadding', '0px');
- tbl.setAttribute('style', 'border: 1px solid white;');
- var row = tbl.insertRow(0);
- var cell = row.insertCell(0);
- cell.setAttribute('class', 'desc');
- cell.setAttribute('align', 'center');
- cell.setAttribute('style', 'border: 1px solid white;');
- cell.innerHTML = 'Metallo';
- cell = row.insertCell(1);
- cell.setAttribute('class', 'desc');
- cell.setAttribute('align', 'center');
- cell.setAttribute('style', 'border: 1px solid white;');
- cell.innerHTML = 'Cristallo';
- cell = row.insertCell(2);
- cell.setAttribute('class', 'desc');
- cell.setAttribute('align', 'center');
- cell.setAttribute('style', 'border: 1px solid white;');
- cell.innerHTML = 'Deuterio';
- var tbEvents = document.getElementById('eventContent');
- var rowLength = tbEvents.rows.length;
- var missionsCount=0;
- var metalSum = 0;
- var crystalSum = 0;
- var deuteriumSum=0;
- var iRow=0;
- while(iRow < rowLength){ //Ciclo sul contenuto della tabella evenContent
- var trMissionType = tbEvents.rows[iRow].getAttribute("data-mission-type");
- if(trMissionType!=null && trMissionType!=''){
- var returnFlight = tbEvents.rows[iRow].getAttribute("data-return-flight");
- if(trMissionType!='16'){ //market missions
- if(
- (trMissionType=='4') || //Market deployment missions
- (trMissionType=='1' && returnFlight == "true") || //Attack missions
- (trMissionType=='3' && returnFlight == "true") || //Transport missions
- (trMissionType=='6' && returnFlight == "true") || //????????
- (trMissionType=='7' && returnFlight == "true") || //Colonization missions
- (trMissionType=='8' && returnFlight == "true") || //Recycle debris field missions
- (trMissionType=='15' && returnFlight == "true") //Expeditions missions
- ){
- var icon_movement_index = tbEvents.rows[iRow].getElementsByTagName("TD").length;
- var sTitle = tbEvents.rows[iRow].getElementsByTagName("TD")[icon_movement_index-5].getElementsByTagName("SPAN")[0].getAttribute("title").trim();
- var start = sTitle.indexOf('<table');
- var end = sTitle.indexOf('</table>', start);
- sTitle = sTitle.slice(start, end) + '</table>';
- var table = document.createElement('table');
- table.innerHTML = sTitle;
- var metIdx = table.rows.length - 3;
- var cryIdx = table.rows.length - 2;
- var deuIdx = table.rows.length - 1;
- var sMetallo = _removeNumberPoints(table.rows[metIdx].getElementsByTagName("TD")[1].innerText);
- var sCristallo = _removeNumberPoints(table.rows[cryIdx].getElementsByTagName("TD")[1].innerText);
- var sDeuterio = _removeNumberPoints(table.rows[deuIdx].getElementsByTagName("TD")[1].innerText);
- metalSum += parseInt(sMetallo);
- crystalSum += parseInt(sCristallo);
- deuteriumSum += parseInt(sDeuterio);
- missionsCount++;
- }
- }
- }
- iRow++;
- }
- _setCookie("fr_metal", metalSum, 1);
- _setCookie("fr_crystal", crystalSum, 1);
- _setCookie("fr_deuterium", deuteriumSum, 1);
- row = tbl.insertRow(1);
- cell = row.insertCell(0);
- cell.setAttribute('class', 'undermark');
- cell.setAttribute('align', 'center');
- cell.setAttribute('style', 'border: 1px solid white;');
- cell.innerHTML = _formatNumber(metalSum, 0, ',', '.');
- cell = row.insertCell(1);
- cell.setAttribute('class', 'undermark');
- cell.setAttribute('align', 'center');
- cell.setAttribute('style', 'border: 1px solid white;');
- cell.innerHTML = _formatNumber(crystalSum, 0, ',', '.');
- cell = row.insertCell(2);
- cell.setAttribute('class', 'undermark');
- cell.setAttribute('align', 'center');
- cell.setAttribute('style', 'border: 1px solid white;');
- cell.innerHTML = _formatNumber(deuteriumSum, 0, ',', '.');
- oCell.appendChild(tbl);
- }
- function _showTotRes(oCell){
- var tbl = document.createElement('table');
- //tbl.setAttribute('width', '100%');
- tbl.setAttribute('cellspacing', '0px');
- tbl.setAttribute('cellpadding', '0px');
- tbl.setAttribute('style', 'border: 1px solid white;');
- var row = tbl.insertRow(0);
- var cell = row.insertCell(0);
- cell.setAttribute('class', 'desc');
- cell.setAttribute('align', 'center');
- cell.setAttribute('style', 'border: 1px solid white;');
- cell.innerHTML = 'Metallo';
- cell = row.insertCell(1);
- cell.setAttribute('class', 'desc');
- cell.setAttribute('align', 'center');
- cell.setAttribute('style', 'border: 1px solid white;');
- cell.innerHTML = 'Cristallo';
- cell = row.insertCell(2);
- cell.setAttribute('class', 'desc');
- cell.setAttribute('align', 'center');
- cell.setAttribute('style', 'border: 1px solid white;');
- cell.innerHTML = 'Deuterio';
- var metalSum = parseInt(_getCookie('fr_metal'));
- var crystalSum = parseInt(_getCookie('fr_crystal'));
- var deuteriumSum = parseInt(_getCookie('fr_deuterium'));
- var ca = document.cookie.split(';');
- for(var i = 0; i < ca.length; i++) {
- var c = ca[i];
- while (c.charAt(0) == ' ') {
- c = c.substring(1);
- }
- if((c.indexOf("_planet") != -1) || (c.indexOf("_moon") != -1)){
- var cv = c.substring(c.indexOf("=")+1).split("_");
- //console.log(parseInt(metalSum) + parseInt(cv[0]));
- metalSum += parseInt(cv[0]);
- crystalSum += parseInt(cv[1]);
- deuteriumSum += parseInt(cv[2]);
- }
- }
- row = tbl.insertRow(1);
- cell = row.insertCell(0);
- cell.setAttribute('class', 'undermark');
- cell.setAttribute('align', 'center');
- cell.setAttribute('style', 'border: 1px solid white;');
- cell.innerHTML = _formatNumber(metalSum, 0, ',', '.');
- cell = row.insertCell(1);
- cell.setAttribute('class', 'undermark');
- cell.setAttribute('align', 'center');
- cell.setAttribute('style', 'border: 1px solid white;');
- cell.innerHTML = _formatNumber(crystalSum, 0, ',', '.');
- cell = row.insertCell(2);
- cell.setAttribute('class', 'undermark');
- cell.setAttribute('align', 'center');
- cell.setAttribute('style', 'border: 1px solid white;');
- cell.innerHTML = _formatNumber(deuteriumSum, 0, ',', '.');
- oCell.appendChild(tbl);
- }
- function showResources(){
- var divInhalt = document.getElementById('middle');
- var divResources = document.createElement('div');
- var tblResources = document.createElement('table');
- divResources.setAttribute('class', 'maincontent');
- divResources.setAttribute('style', 'margin-left:10px;');
- tblResources.setAttribute('width', '100%');
- tblResources.setAttribute('cellspacing', '0');
- tblResources.setAttribute('cellpadding', '0');
- tblResources.setAttribute('border', '0');
- var row = tblResources.insertRow(0);
- var cell = row.insertCell(0);
- cell.setAttribute('align', 'center');
- cell.innerHTML = "<span style='font-size:18px;font-weight:bolder;'>Risorse in volo</span>";
- cell = row.insertCell(1)
- cell.setAttribute('align', 'center');
- cell.setAttribute('style', 'width:50%');
- cell.innerHTML = "<span style='font-size:18px;font-weight:bolder;'>Risorse Totali</span>";
- row = tblResources.insertRow(1);
- cell = row.insertCell(0);
- cell.setAttribute('align', 'center');
- cell.setAttribute('style', 'width:50%');
- _showFlyingRes(cell);
- cell = row.insertCell(1);
- cell.setAttribute('align', 'center');
- _showTotRes(cell);
- divResources.appendChild(tblResources);
- divInhalt.insertBefore(divResources, document.getElementById('overviewcomponent'));
- }
- function showBuildingContdown(){
- var iBuildingDays = 0;
- var iBuildingHours = 0;
- var iBuildingMinutes = 0;
- var oSpanBuilding = document.getElementById('buildingCountdown');
- var index;
- if(oSpanBuilding != null){
- var strTimeBuilding = oSpanBuilding.innerText.split(" ");
- if(strTimeBuilding.length > 1){
- for(index=0;index<strTimeBuilding.length;index++){
- if(index==0 && (strTimeBuilding[index].endsWith("s") || strTimeBuilding[index].endsWith("w"))){
- //Settimane di sviluppo
- iBuildingDays += parseInt(strTimeBuilding[index].substr(0, strTimeBuilding[index].length-1))*7;
- }
- else{
- if(strTimeBuilding[index].endsWith("g") || strTimeBuilding[index].endsWith("d")){
- //giorni
- iBuildingDays += parseInt(strTimeBuilding[index].substr(0, strTimeBuilding[index].length-1));
- }
- else if(strTimeBuilding[index].endsWith("o") || strTimeBuilding[index].endsWith("h")){
- //ore
- iBuildingHours += parseInt(strTimeBuilding[index].substr(0, strTimeBuilding[index].length-1));
- }
- else if(strTimeBuilding[index].endsWith("m")){
- //minuti
- iBuildingMinutes += parseInt(strTimeBuilding[index].substr(0, strTimeBuilding[index].length-1));
- }
- }
- }
- iBuildingHours += iBuildingDays*24;
- iBuildingMinutes += iBuildingHours*60;
- var dBuildDate = new Date();
- dBuildDate.setMinutes(dBuildDate.getMinutes() + iBuildingMinutes);
- var oTR = oSpanBuilding.parentElement.parentElement.parentElement.parentElement.insertRow(4);
- oTR.setAttribute("class", "data");
- var oTD = oTR.insertCell(0);
- oTD.setAttribute("colspan", "2");
- oTD.setAttribute("align", "center");
- oTD.innerHTML = "<br><span class='undermark' style='width:100%'>" + dBuildDate.toLocaleDateString() + " " + dBuildDate.toLocaleTimeString() + "</span>";
- }
- }
- }
- function showResearchContdown(){
- var iBuildingDays = 0;
- var iBuildingHours = 0;
- var iBuildingMinutes = 0;
- var oSpanResearch = document.getElementById('researchCountdown');
- var index;
- if(oSpanResearch != null){
- var strTimeResearch = oSpanResearch.innerText.split(" ");
- if(strTimeResearch.length > 1){
- for(index=0;index<strTimeResearch.length;index++){
- if(index==0 && (strTimeResearch[index].endsWith("s") || strTimeResearch[index].endsWith("w"))){
- //Settimane di sviluppo
- iBuildingDays += parseInt(strTimeResearch[index].substr(0, strTimeResearch[index].length-1))*7;
- }
- else{
- if(strTimeResearch[index].endsWith("g") || strTimeResearch[index].endsWith("d")){
- //giorni
- iBuildingDays += parseInt(strTimeResearch[index].substr(0, strTimeResearch[index].length-1));
- }
- else if(strTimeResearch[index].endsWith("o") || strTimeResearch[index].endsWith("h")){
- //ore
- iBuildingHours += parseInt(strTimeResearch[index].substr(0, strTimeResearch[index].length-1));
- }
- else if(strTimeResearch[index].endsWith("m")){
- //minuti
- iBuildingMinutes += parseInt(strTimeResearch[index].substr(0, strTimeResearch[index].length-1));
- }
- }
- }
- iBuildingHours += iBuildingDays*24;
- iBuildingMinutes += iBuildingHours*60;
- var dResearchDate = new Date();
- dResearchDate.setMinutes(dResearchDate.getMinutes() + iBuildingMinutes);
- var oTR = oSpanResearch.parentElement.parentElement.parentElement.parentElement.insertRow(4);
- oTR.setAttribute("class", "data");
- var oTD = oTR.insertCell(0);
- oTD.setAttribute("colspan", "2");
- oTD.setAttribute("align", "center");
- oTD.innerHTML = "<br><span class='undermark' style='width:100%'>" + dResearchDate.toLocaleDateString() + " " + dResearchDate.toLocaleTimeString() + "</span>";
- }
- }
- }
- function showShipyardContdown(){
- var iBuildingDays = 0;
- var iBuildingHours = 0;
- var iBuildingMinutes = 0;
- var oSpanShipyard = document.getElementById('shipyardCountdown2');
- var index;
- if(oSpanShipyard != null){
- var strTimeShupyard = oSpanShipyard.innerText.split(" ");
- if(strTimeShupyard.length > 1){
- for(index=0;index<strTimeShupyard.length;index++){
- if(index==0 && (strTimeShupyard[index].endsWith("s") || strTimeShupyard[index].endsWith("w"))){
- //Settimane di sviluppo
- iBuildingDays += parseInt(strTimeShupyard[index].substr(0, strTimeShupyard[index].length-1))*7;
- }
- else{
- if(strTimeShupyard[index].endsWith("g") || strTimeShupyard[index].endsWith("d")){
- //giorni
- iBuildingDays += parseInt(strTimeShupyard[index].substr(0, strTimeShupyard[index].length-1));
- }
- else if(strTimeShupyard[index].endsWith("o") || strTimeShupyard[index].endsWith("h")){
- //ore
- iBuildingHours += parseInt(strTimeShupyard[index].substr(0, strTimeShupyard[index].length-1));
- }
- else if(strTimeShupyard[index].endsWith("m")){
- //minuti
- iBuildingMinutes += parseInt(strTimeShupyard[index].substr(0, strTimeShupyard[index].length-1));
- }
- }
- }
- iBuildingHours += iBuildingDays*24;
- iBuildingMinutes += iBuildingHours*60;
- var dShipyardDate = new Date();
- dShipyardDate.setMinutes(dShipyardDate.getMinutes() + iBuildingMinutes);
- var oTR = oSpanShipyard.parentElement.parentElement.parentElement.parentElement.insertRow(6);
- oTR.setAttribute("class", "data");
- var oTD = oTR.insertCell(0);
- oTD.setAttribute("colspan", "2");
- oTD.setAttribute("align", "center");
- oTD.innerHTML = "<br><span class='undermark' style='width:100%'>" + dShipyardDate.toLocaleDateString() + " " + dShipyardDate.toLocaleTimeString() + "</span>";
- }
- }
- }
- function manageFleet(){
- var observer1 = new MutationObserver(function(mutations) { //fleet2 div style change
- mutations.forEach(function(mutationRecord) {
- var metaOPT = _getMeta('ogame-planet-type');
- if(metaOPT != ''){
- var ownCoords = _getMeta('ogame-planet-coordinates');
- var selCoords = document.getElementById('galaxy').getAttribute('value');
- selCoords += ':' + document.getElementById('system').getAttribute('value');
- selCoords += ':' + document.getElementById('position').getAttribute('value');
- if(selCoords == ownCoords){
- if(metaOPT=='planet'){
- document.getElementById('mbutton').click();
- }
- else{
- document.getElementById('pbutton').click();
- }
- }
- }
- observer1.disconnect();
- });
- });
- var observer2 = new MutationObserver(function(mutations) { //fleet3 div style change
- mutations.forEach(function(mutationRecord) {
- var divStatBarFleet = document.getElementById('statusBarFleet');
- var destCoords = divStatBarFleet.getElementsByClassName("targetName")[0].firstChild.nodeValue.trim();
- var ownCoords = '';
- var planetList = document.getElementById('planetList').getElementsByClassName('planet-koords');
- var index=0;
- for(index=0;index<planetList.length;index++){
- ownCoords += planetList[index].innerHTML;
- }
- if(ownCoords.indexOf(destCoords) != -1){
- document.getElementById('missionButton4').click();
- }
- observer2.disconnect();
- });
- });
- var observer3 = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutationRecord) {
- });
- });
- var target2 = document.getElementById('fleet2');
- var target3 = document.getElementById('fleet3');
- var target4 = document.getElementById('errorBoxDecisionContent');
- observer1.observe(target2, { attributes : true, attributeFilter : ['style'] });
- observer2.observe(target3, { attributes : true, attributeFilter : ['style'] });
- }
- function refreshCurPlanetCookie(){
- var metal = _removeNumberPoints(document.getElementById('resources_metal').innerHTML);
- var crystal = _removeNumberPoints(document.getElementById('resources_crystal').innerHTML);
- var deuterium = _removeNumberPoints(document.getElementById('resources_deuterium').innerHTML);
- var ck = _getMeta('ogame-planet-id') + "_" + _getMeta('ogame-planet-type');
- //document.cookie = ck + "; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; //reset cookie befere update
- _setCookie(ck, metal+"_"+crystal+"_"+deuterium, 1);
- }
- function killPlanetsMoon_Tooltip(){
- var divPlanets = document.getElementById('planetList');
- var anchors = divPlanets.getElementsByClassName('planetlink');
- var index=0;
- for(index=0;index<anchors.length;index++){
- var anchorp = anchors[index];
- anchorp.setAttribute('title', '');
- }
- anchors = divPlanets.getElementsByClassName('moonlink');
- for(index=0;index<anchors.length;index++){
- var anchorm = anchors[index];
- anchorm.setAttribute('title', '');
- }
- }
- function _changeTimes(dDelta){
- var tbEvents = document.getElementById('eventContent');
- var rowLength = tbEvents.rows.length;
- var iRow=0;
- while(iRow < rowLength){ //Ciclo sul contenuto della tabella evenContent
- var dtArrivalTime = tbEvents.rows[iRow].getAttribute("data-arrival-time");
- dtArrivalTime = new Date(dtArrivalTime*1000);
- //console.log(dtArrivalTime);
- var str = dtArrivalTime.getHours()+':'+dtArrivalTime.getMinutes()+':'+dtArrivalTime.getSeconds();
- console.log(str);
- tbEvents.rows[iRow].getElementsByClassName("arrivalTime")[0].innerHTML = str;
- iRow++;
- }
- }
- //*** MAIN ***
- //Script runs only with ogame pages
- if (location.href.indexOf('.ogame.gameforge.com') != -1) {
- showBuildingContdown();
- showResearchContdown();
- showShipyardContdown()
- refreshCurPlanetCookie();
- killPlanetsMoon_Tooltip();
- //var dDelta = new Date().getTime() - serverTime.getTime();
- //console.log(Math.trunc(dDelta/3600));
- //_changeTimes(dDelta);
- if (location.href.indexOf('.ogame.gameforge.com/game/index.php?page=ingame&component=overview') != -1) {
- //Overview page - showing all flighting resources
- showResources();
- }
- else if (location.href.indexOf('.ogame.gameforge.com/game/index.php?page=ingame&component=fleetdispatch') != -1) {
- //Fleet page - adding shortcut, preselect destination and preselect deployment missions
- manageFleet();
- }
- else if (location.href.indexOf('.ogame.gameforge.com/game/index.php?page=ingame&component=movement') != -1) {
- //Movements page - adding CR at the end of page.
- var oDiv = document.getElementById('inhalt');
- oDiv.innerHTML += " <br><br><br><br><br> ";
- }
- }
- }) ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement