Skip to content

Instantly share code, notes, and snippets.

@igromanru
Last active August 29, 2015 14:22
Show Gist options
  • Save igromanru/36bf7d38d7d26e140b06 to your computer and use it in GitHub Desktop.
Save igromanru/36bf7d38d7d26e140b06 to your computer and use it in GitHub Desktop.

Revisions

  1. igromanru revised this gist Jun 3, 2015. 1 changed file with 9 additions and 13 deletions.
    22 changes: 9 additions & 13 deletions GalaxyScan.user.js
    Original file line number Diff line number Diff line change
    @@ -12,17 +12,13 @@ var injectedFunction = (function() {

    var GalaxyScan = {
    scanGalaxy: function(galaxyFrom, galaxyTo, sunsysFrom, sunsysTo) {
    var sun = sunsysFrom;
    for(i = galaxyFrom; i <= galaxyTo; i++) {
    for(i = sunsysFrom; i <= sunsysTo; i++) {
    (function(i) {
    setInterval(function(){
    if(i <= galaxyTo) {
    if(sun <= sunsysTo) {
    $('#galaxy_input').val(i);
    $('#system_input').val(sun);
    $('#showbutton').trigger('click');
    sun++;
    }
    if(i <= sunsysTo) {
    $('#galaxy_input').val(galaxyFrom);
    $('#system_input').val(i);
    $('#showbutton').trigger('click');
    }
    }, 500)}
    )(i);
    @@ -93,13 +89,13 @@ function injectHtml() {
    scanDiv.innerHTML = butHtml;
    buttonsDiv.appendChild(scanDiv);

    var guiHtml = '<span class="textlabel">Scan galaxy from</span> \
    var guiHtml = '<span class="textlabel">Scan galaxy</span> \
    <br/> \
    <input type="number" size="5" id="galaxyFrom" min="1" max="9" value="1"> \
    <span class="textlabel">to</span> \
    <input type="number" size="5" id="galaxyTo" min="1" max="9" value="1"> \
    <span class="textlabel" style="display:none">to</span> \
    <input type="number" size="5" id="galaxyTo" min="1" max="9" value="1" style="display:none"> \
    <br/><br/> \
    <span class="textlabel">Scan sun system from</span> \
    <span class="textlabel">Scan sun system</span> \
    <br/> \
    <input type="number" size="5" id="sunsysFrom" min="1" max="499" value="1"> \
    <span class="textlabel">to</span> \
  2. igromanru revised this gist Jun 3, 2015. 1 changed file with 47 additions and 47 deletions.
    94 changes: 47 additions & 47 deletions GalaxyScan.user.js
    Original file line number Diff line number Diff line change
    @@ -2,74 +2,74 @@
    // @name GalaxyScan
    // @namespace IgroGalaxyScan
    // @author Igromanru
    // @include *.ogame.gameforge.com/game/index.php?page=galaxy*
    // @include *.ogame.gameforge.com/game/index.php?*page=galaxy*
    // @description Browsing through the Universe to get the data for GalaxyTool
    // @version 0.1
    // @grant none
    // ==/UserScript==

    var injectedFunction = (function() {

    var GalaxyScan = {
    scanGalaxy: function(galaxyFrom, galaxyTo, sunsysFrom, sunsysTo) {
    var sun = sunsysFrom;
    for(i = galaxyFrom; i <= galaxyTo; i++) {
    (function(i) {
    setInterval(function(){
    if(i <= galaxyTo) {
    if(sun <= sunsysTo) {
    $('#galaxy_input').val(i);
    $('#system_input').val(sun);
    $('#showbutton').trigger('click');
    sun++;
    }
    }
    }, 500)}
    )(i);
    }
    }
    };
    var GalaxyScan = {
    scanGalaxy: function(galaxyFrom, galaxyTo, sunsysFrom, sunsysTo) {
    var sun = sunsysFrom;
    for(i = galaxyFrom; i <= galaxyTo; i++) {
    (function(i) {
    setInterval(function(){
    if(i <= galaxyTo) {
    if(sun <= sunsysTo) {
    $('#galaxy_input').val(i);
    $('#system_input').val(sun);
    $('#showbutton').trigger('click');
    sun++;
    }
    }
    }, 500)}
    )(i);
    }
    }
    };

    $.fn.exists = function () {
    return this.length !== 0;
    };
    $.fn.exists = function () {
    return this.length !== 0;
    };

    $( '#scanOptions' ).dialog({
    autoOpen: false,
    open: function(event, ui) {
    var galaxyNr = $('#galaxy_input').val();
    $('#galaxyFrom').val(galaxyNr);
    $('#galaxyTo').val(galaxyNr);
    },
    buttons: {
    Scan : {
    text: 'Scan',
    id: 'dialogScanBut',
    click: function() {
    $( '#scanOptions' ).dialog({
    autoOpen: false,
    open: function(event, ui) {
    var galaxyNr = $('#galaxy_input').val();
    $('#galaxyFrom').val(galaxyNr);
    $('#galaxyTo').val(galaxyNr);
    },
    buttons: {
    Scan : {
    text: 'Scan',
    id: 'dialogScanBut',
    click: function() {
    var ok = confirm('\Scan can not be stopped!\r\nDo you want to continue?');
    if (ok == true) {
    $( this ).dialog( 'close' );
    GalaxyScan.scanGalaxy($('#galaxyFrom').val(),$('#galaxyTo').val(),$('#sunsysFrom').val(),$('#sunsysTo').val());
    }
    }
    }
    }
    },
    Cancel : {
    text: 'Cancel',
    id: 'dialogScanCancel',
    click: function() {
    $( this ).dialog( 'close' );
    }
    $( this ).dialog( 'close' );
    }
    }
    }
    });
    $('#buttonScanGalaxy' ).click(function() {
    $( '#scanOptions' ).dialog( 'open' );
    });
    $('#buttonScanGalaxy' ).click(function() {
    $( '#scanOptions' ).dialog( 'open' );
    });

    }).toString();

    function getElementByXpath(path) {
    return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    }

    function injectIncludeScript(scriptUrl) {
    @@ -92,7 +92,7 @@ function injectHtml() {
    scanDiv.setAttribute('id',"scanGalaxyButton");
    scanDiv.innerHTML = butHtml;
    buttonsDiv.appendChild(scanDiv);

    var guiHtml = '<span class="textlabel">Scan galaxy from</span> \
    <br/> \
    <input type="number" size="5" id="galaxyFrom" min="1" max="9" value="1"> \
    @@ -108,22 +108,22 @@ function injectHtml() {
    divGui.setAttribute('id',"scanOptions");
    divGui.setAttribute('title',"GalaxyScan");
    divGui.innerHTML = guiHtml;
    document.getElementsByTagName("body")[0].appendChild(divGui);
    document.getElementsByTagName("body")[0].appendChild(divGui);
    }

    function injectCss() {
    var scanButtonCss = '#buttonScanGalaxy { color: #fff; display: block } #buttonScanGalaxy:hover { color: #9c0; }';
    var guiCss = '#galaxyFrom, #galaxyTo, #sunsysFrom, #sunsysTo { width: 50px;}';
    var style = document.createElement('style');

    style.type = 'text/css';
    style.innerHTML = scanButtonCss + guiCss;

    document.getElementsByTagName("head")[0].appendChild(style);
    }

    if (document.body) {
    injectIncludeScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js");
    injectIncludeScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js");
    injectHtml();
    injectCss();
    injectScript(injectedFunction);
  3. igromanru revised this gist Jun 3, 2015. 1 changed file with 27 additions and 4 deletions.
    31 changes: 27 additions & 4 deletions GalaxyScan.user.js
    Original file line number Diff line number Diff line change
    @@ -11,8 +11,22 @@
    var injectedFunction = (function() {

    var GalaxyScan = {
    init: function() {

    scanGalaxy: function(galaxyFrom, galaxyTo, sunsysFrom, sunsysTo) {
    var sun = sunsysFrom;
    for(i = galaxyFrom; i <= galaxyTo; i++) {
    (function(i) {
    setInterval(function(){
    if(i <= galaxyTo) {
    if(sun <= sunsysTo) {
    $('#galaxy_input').val(i);
    $('#system_input').val(sun);
    $('#showbutton').trigger('click');
    sun++;
    }
    }
    }, 500)}
    )(i);
    }
    }
    };

    @@ -21,13 +35,22 @@ $.fn.exists = function () {
    };

    $( '#scanOptions' ).dialog({
    autoOpen: false,
    autoOpen: false,
    open: function(event, ui) {
    var galaxyNr = $('#galaxy_input').val();
    $('#galaxyFrom').val(galaxyNr);
    $('#galaxyTo').val(galaxyNr);
    },
    buttons: {
    Scan : {
    text: 'Scan',
    id: 'dialogScanBut',
    click: function() {
    $( this ).dialog( 'close' );
    var ok = confirm('\Scan can not be stopped!\r\nDo you want to continue?');
    if (ok == true) {
    $( this ).dialog( 'close' );
    GalaxyScan.scanGalaxy($('#galaxyFrom').val(),$('#galaxyTo').val(),$('#sunsysFrom').val(),$('#sunsysTo').val());
    }
    }
    },
    Cancel : {
  4. igromanru revised this gist Jun 2, 2015. 1 changed file with 48 additions and 10 deletions.
    58 changes: 48 additions & 10 deletions GalaxyScan.user.js
    Original file line number Diff line number Diff line change
    @@ -11,18 +11,37 @@
    var injectedFunction = (function() {

    var GalaxyScan = {
    init: function() {
    init: function() {

    }
    };

    $.fn.exists = function () {
    return this.length !== 0;
    };

    function doScanGalaxy() {
    GalaxyScan.init();
    }
    $( '#scanOptions' ).dialog({
    autoOpen: false,
    buttons: {
    Scan : {
    text: 'Scan',
    id: 'dialogScanBut',
    click: function() {
    $( this ).dialog( 'close' );
    }
    },
    Cancel : {
    text: 'Cancel',
    id: 'dialogScanCancel',
    click: function() {
    $( this ).dialog( 'close' );
    }
    }
    }
    });
    $('#buttonScanGalaxy' ).click(function() {
    $( '#scanOptions' ).dialog( 'open' );
    });

    }).toString();

    @@ -44,26 +63,45 @@ function injectScript(functionString) {
    }

    function injectHtml() {
    var butHtml = '<a id="buttonScanGalaxy" href="javascript:void(0);" ><span class="bleft"></span><span class="text">Scan Galaxy</span><span class="bright"></span></a>';
    var buttonsDiv = getElementByXpath("//tr[@id='galaxyheadbg']/td/div");
    var scanDiv = document.createElement('div');
    scanDiv.setAttribute('id',"scanGalaxyButton");
    scanDiv.innerHTML = '<a id="buttonScanGalaxy" onclick="doScanGalaxy();" href="javascript:void(0);"><span class="bleft"></span><span class="text">Scan Galaxy</span><span class="bright"></span></a>';
    buttonsDiv.appendChild(scanDiv);
    scanDiv.innerHTML = butHtml;
    buttonsDiv.appendChild(scanDiv);

    var guiHtml = '<span class="textlabel">Scan galaxy from</span> \
    <br/> \
    <input type="number" size="5" id="galaxyFrom" min="1" max="9" value="1"> \
    <span class="textlabel">to</span> \
    <input type="number" size="5" id="galaxyTo" min="1" max="9" value="1"> \
    <br/><br/> \
    <span class="textlabel">Scan sun system from</span> \
    <br/> \
    <input type="number" size="5" id="sunsysFrom" min="1" max="499" value="1"> \
    <span class="textlabel">to</span> \
    <input type="number" size="5" id="sunsysTo" min="1" max="499" value="499">';
    var divGui = document.createElement('div');
    divGui.setAttribute('id',"scanOptions");
    divGui.setAttribute('title',"GalaxyScan");
    divGui.innerHTML = guiHtml;
    document.getElementsByTagName("body")[0].appendChild(divGui);
    }

    function injectCss() {
    var scanButtonCss = '#buttonScanGalaxy { color: #fff; display: block } #buttonScanGalaxy:hover { color: #9c0; }';
    var guiCss = '#galaxyFrom, #galaxyTo, #sunsysFrom, #sunsysTo { width: 50px;}';
    var style = document.createElement('style');

    style.type = 'text/css';
    style.innerHTML = scanButtonCss;
    style.innerHTML = scanButtonCss + guiCss;

    document.getElementsByTagName("head")[0].appendChild(style);
    }

    if (document.body) {
    injectIncludeScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js");
    injectScript(injectedFunction);
    injectIncludeScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js");
    injectHtml();
    injectCss();
    injectScript(injectedFunction);
    }
  5. igromanru revised this gist Jun 2, 2015. 1 changed file with 19 additions and 4 deletions.
    23 changes: 19 additions & 4 deletions GalaxyScan.user.js
    Original file line number Diff line number Diff line change
    @@ -8,24 +8,38 @@
    // @grant none
    // ==/UserScript==

    var scriptFunc = (function() {
    var injectedFunction = (function() {

    var GalaxyScan = {
    init: function() {

    }
    };

    $.fn.exists = function () {
    return this.length !== 0;
    };

    function doScanGalaxy() {
    GalaxyScan.init();
    }

    }).toString();

    function getElementByXpath(path) {
    return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    }

    function injectScript (myFunc) {
    function injectIncludeScript(scriptUrl) {
    var script = document.createElement ("script");
    script.setAttribute ("src", scriptUrl);
    document.getElementsByTagName("head")[0].appendChild(script);
    }

    function injectScript(functionString) {
    var script = document.createElement ("script");
    script.setAttribute ("type", "application/javascript");
    script.textContent = "(" + myFunc + ") ();";
    script.textContent = "(" + functionString + ") ();";
    document.body.appendChild (script);
    }

    @@ -48,7 +62,8 @@ function injectCss() {
    }

    if (document.body) {
    //injectScript(scriptFunc);
    injectIncludeScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js");
    injectScript(injectedFunction);
    injectHtml();
    injectCss();
    }
  6. igromanru revised this gist Jun 2, 2015. 1 changed file with 15 additions and 4 deletions.
    19 changes: 15 additions & 4 deletions GalaxyScan.user.js
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,9 @@ $.fn.exists = function () {

    }).toString();

    function getElementByXpath(path) {
    return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    }

    function injectScript (myFunc) {
    var script = document.createElement ("script");
    @@ -26,18 +29,26 @@ function injectScript (myFunc) {
    document.body.appendChild (script);
    }

    function injectHtml() {
    var buttonsDiv = getElementByXpath("//tr[@id='galaxyheadbg']/td/div");
    var scanDiv = document.createElement('div');
    scanDiv.setAttribute('id',"scanGalaxyButton");
    scanDiv.innerHTML = '<a id="buttonScanGalaxy" onclick="doScanGalaxy();" href="javascript:void(0);"><span class="bleft"></span><span class="text">Scan Galaxy</span><span class="bright"></span></a>';
    buttonsDiv.appendChild(scanDiv);
    }

    function injectCss() {
    var recallImage = "data:image/gif;base64,R0lGODlhEAAQAKIAAISbrAAAAP///2+JnVx2iwAAAAAAAAAAACH5BAAAAAAALAAAAAAQABAAAAMqGLTcrS7KSautIut9mejLtwwkKZTliQ5Atg4qus1x2dbviud875eBHzABADs=";
    var recallCss = '.oaf_recall_icon {background-image: url('+recallImage+'); background-repeat: no-repeat !important;} #eventHeader .recall_eventlist_reload {position: absolute; left: 14px; margin: 4px 0;}';
    var scanButtonCss = '#buttonScanGalaxy { color: #fff; display: block } #buttonScanGalaxy:hover { color: #9c0; }';
    var style = document.createElement('style');

    style.type = 'text/css';
    style.innerHTML = recallCss;
    style.innerHTML = scanButtonCss;

    document.getElementsByTagName("head")[0].appendChild(style);
    }

    if (document.body) {
    injectScript(scriptFunc);
    //injectScript(scriptFunc);
    injectHtml();
    injectCss();
    }
  7. igromanru revised this gist Jun 1, 2015. 1 changed file with 1 addition and 239 deletions.
    240 changes: 1 addition & 239 deletions GalaxyScan.user.js
    Original file line number Diff line number Diff line change
    @@ -2,257 +2,19 @@
    // @name GalaxyScan
    // @namespace IgroGalaxyScan
    // @author Igromanru
    // @include *.ogame.gameforge.com/game/*
    // @include *.ogame.gameforge.com/game/index.php?page=galaxy*
    // @description Browsing through the Universe to get the data for GalaxyTool
    // @version 0.1
    // @grant none
    // ==/UserScript==

    var scriptFunc = (function() {
    var Recall = {
    getMovement: true,
    getEvents: true,
    pendingMovement: false,
    pendingEvents: false,
    availableMovements: [],
    availableEvents: {},
    currentPage: "",
    universeFull: "",
    missionType: {expedition:15, deploy:4, acsAttack:2, attack:1},

    init: function() {
    var observer = new MutationObserver(Recall.initAppendRecall);
    var target = document.getElementById('eventboxContent');

    Recall.universeFull = document.getElementsByName("ogame-universe")[0].content;
    Recall.currentPage = (window.location+"").match(/page=[^&]+((?=&)|(?=#)|)/g)[0].replace("page=", "");

    /* Disable FastRecall on fleet1/2/3 and movement pages */
    if (Recall.currentPage !== "movement" &&
    Recall.currentPage !== "fleet1" &&
    Recall.currentPage !== "fleet2" &&
    Recall.currentPage !== "fleet3") {

    observer.observe(target, {childList: true});

    /* If events are not hidden (Options->Display->Always show events */
    if ($('table#eventContent').exists()) {
    Recall.initAppendRecall();
    }
    }
    },

    initAppendRecall: function(mutations) {
    if ($('table#eventContent').exists()) {
    /* Get the "fleet movement" page information only once - when the fleets eventbox is showen for the first time */
    if (Recall.getMovement === true && Recall.pendingMovement === false) {
    Recall.pendingMovement = true;
    Recall.getFleetMovement();
    }

    /* Get a clean eventlist content only once.
    This is done because AGO or other tools might alter the original information (eg. change clocks values to local time)
    */
    if (Recall.getEvents === true && Recall.pendingEvents === false) {
    Recall.pendingEvents = true;
    Recall.getEventsList();
    }

    if (Recall.getEvents === false && Recall.getMovement === false) {
    Recall.doAppendRecall();
    }
    }
    },

    doAppendRecall: function() {
    if ($('table#eventContent').exists()) {
    Recall.appendEventlistReload();

    $('table#eventContent tr[data-return-flight="false"]').each(function() {
    var row = $(this);
    var isAllianceAttack = row.hasClass('allianceAttack');

    if (isAllianceAttack === false) {
    var missionType = parseInt(row.attr('data-mission-type'));
    var eventRowId;

    if (missionType !== Recall.missionType.acsAttack)
    eventRowId = parseInt(row.attr('id').match(/\d+/)[0]);
    else
    eventRowId = parseInt(row.find('td.icon_movement span.tooltip').attr('data-federation-user-id').match(/\d+/)[0]);

    if (Recall.availableEvents[eventRowId]) {
    var returnId = Recall.matchEventWithMovement(Recall.availableEvents[eventRowId]);

    if (returnId !== "" && returnId !== "multipleMatch")
    row.append('<td class="oaf_recall_td"><a class="oaf_recall_icon icon_link" oaf_recall_id='+returnId+'></a></td>');
    }
    }
    });

    $('.oaf_recall_icon').click(function(){
    var recallId = $(this).attr('oaf_recall_id');
    var url = 'http://'+Recall.universeFull+'/game/index.php?page=movement&return='+recallId;

    $.get(url, function(response) {$('#eventHeader .icon_reload').click();});
    });
    }
    },

    appendEventlistReload: function() {
    if (!window.AGO && $('#eventHeader .icon_reload.recall_eventlist_reload').exists() === false) {
    $('#eventHeader').prepend('<a href="javascript:void(0)"><span class="icon icon_reload recall_eventlist_reload"></span></a>').click(function(){
    $.get("/game/index.php?page=eventList&ajax=1", function (a) { $("#eventboxContent").html(a);});
    });
    }
    },

    getFleetMovement: function() {
    /* Get the "fleet movement" page information; should be called only once */
    var url = 'http://'+Recall.universeFull+'/game/index.php?page=movement';

    $.get(url, Recall.parseFleetMovement);
    },

    parseFleetMovement: function(html) {
    /* get own fleet flights except returning ones */
    var page = $(html);
    Recall.availableMovements = [];

    page.find('.fleetDetails[data-return-flight="false"]').each(function() {
    var item = $(this);
    var info = {};

    info.arrivalTime = item.attr('data-arrival-time');
    info.originPosStr = item.find('.originCoords').text();
    info.destinationPosStr = item.find('.destinationCoords').text();
    info.returnId = item.attr('id').match(/\d+/g)[0];
    info.missionType = parseInt(item.attr('data-mission-type'));

    var retTime = item.find('span.nextabsTime');
    if (retTime.exists())
    info.retClock = retTime.text().trim();
    else
    info.retClock = "none";

    /* console.log("New movement: " + JSON.stringify(info)); */
    Recall.availableMovements.push(info);
    });

    Recall.pendingMovement = false;
    Recall.getMovement = false;

    /* On galaxy view: the miniFleetToken is invalidated after getting the fleetMovement page.
    As a result, the first spy attempt will fail ('an error has occured'). We get a valid token
    by sending an invalid spy request and using the newToken from the response.
    */
    if (Recall.currentPage === "galaxy") {
    var url = 'http://'+Recall.universeFull+'/game/index.php?page=minifleet&ajax=1';
    var data = 'mission=6&token=none&speed=10';
    $.post(url, data, function(resp){
    try {
    window.miniFleetToken = JSON.parse(resp).newToken;
    } catch(e) {}
    });
    }

    Recall.doAppendRecall();
    },

    getEventsList: function() {
    /* get eventlist content; should be called only once */
    $.get("/game/index.php?page=eventList&ajax=1", function (a) {
    var item = $('<div>'+a+'</div>');
    Recall.availableEvents = {};

    item.find('table#eventContent tr[data-return-flight="false"]').each(function() {
    var row = $(this);
    var isFriendly = row.find('.countDown.friendly').exists();
    var isAllianceAttack = row.hasClass('allianceAttack');

    if (isFriendly === true && isAllianceAttack === false) {
    var info = {};
    info.arrivalTime = row.attr('data-arrival-time');
    info.originPosStr = row.find('.coordsOrigin').text().trim();
    info.destinationPosStr = row.find('.destCoords').text().trim();
    info.missionType = parseInt(row.attr('data-mission-type'));

    var eventRowId;
    if (info.missionType !== Recall.missionType.acsAttack) {
    eventRowId = parseInt(row.attr('id').match(/\d+/)[0]);
    }
    else {
    eventRowId = parseInt(row.find('td.icon_movement span.tooltip').attr('data-federation-user-id').match(/\d+/)[0]);

    var unionName = row.attr('class').match(/union\d+/)[0];
    /* console.log(unionName + " " + eventRowId + " " + item.find('tr.partnerInfo.' + unionName).length); */
    if (unionName.indexOf("" + eventRowId) !== -1 && item.find('tr.partnerInfo.' + unionName).length === 1)
    info.missionType = Recall.missionType.attack;
    }

    var pairRowId = eventRowId + (info.missionType === Recall.missionType.expedition ? 2 : 1);
    var retRow = item.find('#eventRow-'+pairRowId+'[data-return-flight="true"]');

    if (retRow.exists()) {
    var retTime = retRow.attr('data-arrival-time');
    var origPosRet = retRow.find('.coordsOrigin').text().trim();
    var destPosRet = retRow.find('.destCoords').text().trim();

    if (origPosRet === info.originPosStr && destPosRet === info.destinationPosStr) {
    info.retClock = retRow.find('td.arrivalTime').text().trim();
    }
    else {
    info.retClock = "none";
    }
    }
    else {
    info.retClock = "none";
    }

    /* console.log("New event row: " + JSON.stringify(info)); */
    Recall.availableEvents[eventRowId] = info;
    }
    });

    $("#eventboxContent").html(a);
    Recall.getEvents = false;
    Recall.pendingEvents = false;
    });
    },

    matchEventWithMovement: function(evInfo) {
    var retVal = "";
    for (var m in Recall.availableMovements) {
    if (Recall.availableMovements.hasOwnProperty(m) === false)
    continue;

    var mvInfo = Recall.availableMovements[m];

    if (mvInfo.arrivalTime === evInfo.arrivalTime &&
    mvInfo.originPosStr === evInfo.originPosStr &&
    mvInfo.destinationCoords === evInfo.destinationCoords &&
    mvInfo.missionType === evInfo.missionType) {

    if (mvInfo.missionType === Recall.missionType.deploy ||
    (mvInfo.retClock === evInfo.retClock && mvInfo.retClock !== "none")) {

    if (retVal === "")
    retVal = mvInfo.returnId;
    else
    retVal = "multipleMatch";
    }
    }
    }

    return retVal;
    }
    };

    $.fn.exists = function () {
    return this.length !== 0;
    };

    Recall.init();

    }).toString();

  8. igromanru created this gist Jun 1, 2015.
    281 changes: 281 additions & 0 deletions GalaxyScan.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,281 @@
    // ==UserScript==
    // @name GalaxyScan
    // @namespace IgroGalaxyScan
    // @author Igromanru
    // @include *.ogame.gameforge.com/game/*
    // @description Browsing through the Universe to get the data for GalaxyTool
    // @version 0.1
    // @grant none
    // ==/UserScript==

    var scriptFunc = (function() {
    var Recall = {
    getMovement: true,
    getEvents: true,
    pendingMovement: false,
    pendingEvents: false,
    availableMovements: [],
    availableEvents: {},
    currentPage: "",
    universeFull: "",
    missionType: {expedition:15, deploy:4, acsAttack:2, attack:1},

    init: function() {
    var observer = new MutationObserver(Recall.initAppendRecall);
    var target = document.getElementById('eventboxContent');

    Recall.universeFull = document.getElementsByName("ogame-universe")[0].content;
    Recall.currentPage = (window.location+"").match(/page=[^&]+((?=&)|(?=#)|)/g)[0].replace("page=", "");

    /* Disable FastRecall on fleet1/2/3 and movement pages */
    if (Recall.currentPage !== "movement" &&
    Recall.currentPage !== "fleet1" &&
    Recall.currentPage !== "fleet2" &&
    Recall.currentPage !== "fleet3") {

    observer.observe(target, {childList: true});

    /* If events are not hidden (Options->Display->Always show events */
    if ($('table#eventContent').exists()) {
    Recall.initAppendRecall();
    }
    }
    },

    initAppendRecall: function(mutations) {
    if ($('table#eventContent').exists()) {
    /* Get the "fleet movement" page information only once - when the fleets eventbox is showen for the first time */
    if (Recall.getMovement === true && Recall.pendingMovement === false) {
    Recall.pendingMovement = true;
    Recall.getFleetMovement();
    }

    /* Get a clean eventlist content only once.
    This is done because AGO or other tools might alter the original information (eg. change clocks values to local time)
    */
    if (Recall.getEvents === true && Recall.pendingEvents === false) {
    Recall.pendingEvents = true;
    Recall.getEventsList();
    }

    if (Recall.getEvents === false && Recall.getMovement === false) {
    Recall.doAppendRecall();
    }
    }
    },

    doAppendRecall: function() {
    if ($('table#eventContent').exists()) {
    Recall.appendEventlistReload();

    $('table#eventContent tr[data-return-flight="false"]').each(function() {
    var row = $(this);
    var isAllianceAttack = row.hasClass('allianceAttack');

    if (isAllianceAttack === false) {
    var missionType = parseInt(row.attr('data-mission-type'));
    var eventRowId;

    if (missionType !== Recall.missionType.acsAttack)
    eventRowId = parseInt(row.attr('id').match(/\d+/)[0]);
    else
    eventRowId = parseInt(row.find('td.icon_movement span.tooltip').attr('data-federation-user-id').match(/\d+/)[0]);

    if (Recall.availableEvents[eventRowId]) {
    var returnId = Recall.matchEventWithMovement(Recall.availableEvents[eventRowId]);

    if (returnId !== "" && returnId !== "multipleMatch")
    row.append('<td class="oaf_recall_td"><a class="oaf_recall_icon icon_link" oaf_recall_id='+returnId+'></a></td>');
    }
    }
    });

    $('.oaf_recall_icon').click(function(){
    var recallId = $(this).attr('oaf_recall_id');
    var url = 'http://'+Recall.universeFull+'/game/index.php?page=movement&return='+recallId;

    $.get(url, function(response) {$('#eventHeader .icon_reload').click();});
    });
    }
    },

    appendEventlistReload: function() {
    if (!window.AGO && $('#eventHeader .icon_reload.recall_eventlist_reload').exists() === false) {
    $('#eventHeader').prepend('<a href="javascript:void(0)"><span class="icon icon_reload recall_eventlist_reload"></span></a>').click(function(){
    $.get("/game/index.php?page=eventList&ajax=1", function (a) { $("#eventboxContent").html(a);});
    });
    }
    },

    getFleetMovement: function() {
    /* Get the "fleet movement" page information; should be called only once */
    var url = 'http://'+Recall.universeFull+'/game/index.php?page=movement';

    $.get(url, Recall.parseFleetMovement);
    },

    parseFleetMovement: function(html) {
    /* get own fleet flights except returning ones */
    var page = $(html);
    Recall.availableMovements = [];

    page.find('.fleetDetails[data-return-flight="false"]').each(function() {
    var item = $(this);
    var info = {};

    info.arrivalTime = item.attr('data-arrival-time');
    info.originPosStr = item.find('.originCoords').text();
    info.destinationPosStr = item.find('.destinationCoords').text();
    info.returnId = item.attr('id').match(/\d+/g)[0];
    info.missionType = parseInt(item.attr('data-mission-type'));

    var retTime = item.find('span.nextabsTime');
    if (retTime.exists())
    info.retClock = retTime.text().trim();
    else
    info.retClock = "none";

    /* console.log("New movement: " + JSON.stringify(info)); */
    Recall.availableMovements.push(info);
    });

    Recall.pendingMovement = false;
    Recall.getMovement = false;

    /* On galaxy view: the miniFleetToken is invalidated after getting the fleetMovement page.
    As a result, the first spy attempt will fail ('an error has occured'). We get a valid token
    by sending an invalid spy request and using the newToken from the response.
    */
    if (Recall.currentPage === "galaxy") {
    var url = 'http://'+Recall.universeFull+'/game/index.php?page=minifleet&ajax=1';
    var data = 'mission=6&token=none&speed=10';
    $.post(url, data, function(resp){
    try {
    window.miniFleetToken = JSON.parse(resp).newToken;
    } catch(e) {}
    });
    }

    Recall.doAppendRecall();
    },

    getEventsList: function() {
    /* get eventlist content; should be called only once */
    $.get("/game/index.php?page=eventList&ajax=1", function (a) {
    var item = $('<div>'+a+'</div>');
    Recall.availableEvents = {};

    item.find('table#eventContent tr[data-return-flight="false"]').each(function() {
    var row = $(this);
    var isFriendly = row.find('.countDown.friendly').exists();
    var isAllianceAttack = row.hasClass('allianceAttack');

    if (isFriendly === true && isAllianceAttack === false) {
    var info = {};
    info.arrivalTime = row.attr('data-arrival-time');
    info.originPosStr = row.find('.coordsOrigin').text().trim();
    info.destinationPosStr = row.find('.destCoords').text().trim();
    info.missionType = parseInt(row.attr('data-mission-type'));

    var eventRowId;
    if (info.missionType !== Recall.missionType.acsAttack) {
    eventRowId = parseInt(row.attr('id').match(/\d+/)[0]);
    }
    else {
    eventRowId = parseInt(row.find('td.icon_movement span.tooltip').attr('data-federation-user-id').match(/\d+/)[0]);

    var unionName = row.attr('class').match(/union\d+/)[0];
    /* console.log(unionName + " " + eventRowId + " " + item.find('tr.partnerInfo.' + unionName).length); */
    if (unionName.indexOf("" + eventRowId) !== -1 && item.find('tr.partnerInfo.' + unionName).length === 1)
    info.missionType = Recall.missionType.attack;
    }

    var pairRowId = eventRowId + (info.missionType === Recall.missionType.expedition ? 2 : 1);
    var retRow = item.find('#eventRow-'+pairRowId+'[data-return-flight="true"]');

    if (retRow.exists()) {
    var retTime = retRow.attr('data-arrival-time');
    var origPosRet = retRow.find('.coordsOrigin').text().trim();
    var destPosRet = retRow.find('.destCoords').text().trim();

    if (origPosRet === info.originPosStr && destPosRet === info.destinationPosStr) {
    info.retClock = retRow.find('td.arrivalTime').text().trim();
    }
    else {
    info.retClock = "none";
    }
    }
    else {
    info.retClock = "none";
    }

    /* console.log("New event row: " + JSON.stringify(info)); */
    Recall.availableEvents[eventRowId] = info;
    }
    });

    $("#eventboxContent").html(a);
    Recall.getEvents = false;
    Recall.pendingEvents = false;
    });
    },

    matchEventWithMovement: function(evInfo) {
    var retVal = "";
    for (var m in Recall.availableMovements) {
    if (Recall.availableMovements.hasOwnProperty(m) === false)
    continue;

    var mvInfo = Recall.availableMovements[m];

    if (mvInfo.arrivalTime === evInfo.arrivalTime &&
    mvInfo.originPosStr === evInfo.originPosStr &&
    mvInfo.destinationCoords === evInfo.destinationCoords &&
    mvInfo.missionType === evInfo.missionType) {

    if (mvInfo.missionType === Recall.missionType.deploy ||
    (mvInfo.retClock === evInfo.retClock && mvInfo.retClock !== "none")) {

    if (retVal === "")
    retVal = mvInfo.returnId;
    else
    retVal = "multipleMatch";
    }
    }
    }

    return retVal;
    }
    };

    $.fn.exists = function () {
    return this.length !== 0;
    };

    Recall.init();

    }).toString();


    function injectScript (myFunc) {
    var script = document.createElement ("script");
    script.setAttribute ("type", "application/javascript");
    script.textContent = "(" + myFunc + ") ();";
    document.body.appendChild (script);
    }

    function injectCss() {
    var recallImage = "data:image/gif;base64,R0lGODlhEAAQAKIAAISbrAAAAP///2+JnVx2iwAAAAAAAAAAACH5BAAAAAAALAAAAAAQABAAAAMqGLTcrS7KSautIut9mejLtwwkKZTliQ5Atg4qus1x2dbviud875eBHzABADs=";
    var recallCss = '.oaf_recall_icon {background-image: url('+recallImage+'); background-repeat: no-repeat !important;} #eventHeader .recall_eventlist_reload {position: absolute; left: 14px; margin: 4px 0;}';
    var style = document.createElement('style');

    style.type = 'text/css';
    style.innerHTML = recallCss;

    document.getElementsByTagName("head")[0].appendChild(style);
    }

    if (document.body) {
    injectScript(scriptFunc);
    injectCss();
    }