User Script Extension: "FleetWalk" to quickly flip through your carriers

In my current game, I have a ton of carriers, many on loops, and had occasionally noticed some with incorrectly set instructions. Some were accidents, some I think were just orders that didn’t make it to the server for whatever reason, but it was too many to check one by one from the galaxy screen or on the map.

This will add “previous” and “next” arrows (left and right arrow keys work on them) to the carrier detail screen, and they will loop through carriers in whatever order you had them last listed in the galaxy screen’s “Carrier” tab.

Example:

  1. Here’s my 3 carriers in the galaxy screen, sorted by decreasing number of waypoints:
  2. Click the name of the top carrier to bring up it’s detail screen, and note the previous and next buttons at the top:
  3. Clicking on the next button takes you to the next carrier using the order you set in the galaxy screen:

And that’s pretty much it! Maybe something you don’t always want to do but it’s been pretty convenient to sanity-check my large number of carriers.

Bookmarklet (remove leading ‘+’):

+javascript:(function(){var e=NeptunesPride.universe,t=NeptunesPride.npui;t.FleetInspector=function(){var r=t.Screen();r.heading.rawHTML(e.selectedFleet.n),Crux.IconButton("icon-help","show_help","fleets").grid(24.5,0,3,3).roost(r),Crux.IconButton("icon-doc-text","show_screen","combat_calculator").grid(22,0,3,3).roost(r);var o="my_fleet";e.selectedFleet.player!==e.player&&(o="enemy_fleet");var l=[];for(var n in e.galaxy.fleets)"my_fleets"===e.fleetDirectory.filter?e.galaxy.fleets[n].player===e.player&&l.push(e.galaxy.fleets[n]):l.push(e.galaxy.fleets[n]);"name"===e.fleetDirectory.sortBy&&l.sort(function(t,r){var o=-1;return t.n<r.n&&(o=1),o*=e.fleetDirectory.invert}),("st"===e.fleetDirectory.sortBy||"puid"===e.fleetDirectory.sortBy||"etaFirst"===e.fleetDirectory.sortBy||"eta"===e.fleetDirectory.sortBy)&&l.sort(function(t,r){var o=r[e.fleetDirectory.sortBy]-t[e.fleetDirectory.sortBy];return 0===o&&(o=1,t.n<r.n&&(o=-1)),o*=e.fleetDirectory.invert}),"w"===e.fleetDirectory.sortBy&&l.sort(function(t,r){var o=r.path.length-t.path.length;return 0===o&&(o=1,t.n<r.n&&(o=-1)),o*=e.fleetDirectory.invert});for(var i=-1,s=0,c=l.length;c>s;s++)if(l[s].uid===e.selectedFleet.uid){i=s;break}return-1!==i&&(Crux.IconButton("icon-right-open","key_right","diplomacy").grid(19.5,0,3,3).roost(r),Crux.IconButton("icon-left-open","key_left","diplomacy").grid(17,0,3,3).roost(r)),Crux.Text(o,"rel pad12 col_black txt_center").format({colourBox:e.selectedFleet.colourBox,hyperlinkedAlias:e.selectedFleet.hyperlinkedAlias}).roost(r),t.FleetStatus().roost(r),t.FleetNav().roost(r),e.selectedFleet.player===e.player&&t.FleetPremium().roost(r),t.PlayerPanel(e.selectedFleet.player,!0).roost(r),r.onLastFleet=function(){-1!==i&&(++i,i>l.length-1&&(i=0),t.trigger("show_fleet_screen_uid",l[i].uid))},r.onNextFleet=function(){-1!==i&&(--i,0>i&&(i=l.length-1),t.trigger("show_fleet_screen_uid",l[i].uid))},-1!==i&&(r.on("key_left",r.onLastFleet),r.on("key_right",r.onNextFleet)),r},NeptunesPride.np.trigger("map_refresh")})();

See the top of this post for information on how to create the bookmarklet.


Un-minified code:

// MIT License
//
// Copyright (c) 2016 Jay Kyburz, Dakota Hawkins
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

/* globals Crux: true, NeptunesPride: true */
(function () {
    var universe = NeptunesPride.universe;
    var npui = NeptunesPride.npui;

    // -------------------------------------------------------------------------
    npui.FleetInspector = function () {
        var fleetInspector = npui.Screen();
        fleetInspector.heading.rawHTML(universe.selectedFleet.n);

        Crux.IconButton("icon-help", "show_help", "fleets")
            .grid(24.5, 0, 3, 3)
            .roost(fleetInspector);

        Crux.IconButton("icon-doc-text", "show_screen", "combat_calculator")
            .grid(24.5 - 2.5, 0, 3, 3)
            .roost(fleetInspector);

        var fleetKind = "my_fleet";
        if (universe.selectedFleet.player !== universe.player) {
            fleetKind = "enemy_fleet";
        }

        var sortedFleets = [];
        for (var prop in universe.galaxy.fleets) {
            if (universe.fleetDirectory.filter === "my_fleets") {
                if (universe.galaxy.fleets[prop].player === universe.player) {
                    sortedFleets.push(universe.galaxy.fleets[prop]);
                }
            } else {
                sortedFleets.push(universe.galaxy.fleets[prop]);
            }
        }

        if (universe.fleetDirectory.sortBy === "name") {
            sortedFleets.sort(function (a, b) {
                var result = -1;
                if (a.n < b.n) {
                    result = 1;
                }
                result *= universe.fleetDirectory.invert;
                return result;
            });
        }

        if (universe.fleetDirectory.sortBy === "st" ||
            universe.fleetDirectory.sortBy === "puid" ||
            universe.fleetDirectory.sortBy === "etaFirst" ||
            universe.fleetDirectory.sortBy === "eta") {
            sortedFleets.sort(function (a, b) {
                var result = b[universe.fleetDirectory.sortBy] - a[universe.fleetDirectory.sortBy];
                if (result === 0) {
                    result = 1;
                    if (a.n < b.n) {
                        result = -1;
                    }
                }
                result *= universe.fleetDirectory.invert;
                return result;
            });
        }

        if (universe.fleetDirectory.sortBy === "w") {
            sortedFleets.sort(function (a, b) {
                var result = b.path.length - a.path.length;
                if (result === 0) {
                    result = 1;
                    if (a.n < b.n) {
                        result = -1;
                    }
                }
                result *= universe.fleetDirectory.invert;
                return result;
            });
        }

        var sortedFleetIndex = -1;
        for(var i = 0, len = sortedFleets.length; i < len; i++) {
            if (sortedFleets[i].uid === universe.selectedFleet.uid) {
                sortedFleetIndex = i;
                break;
            }
        }

        //console.log("FleetInspector Init Done: sortedFleets.length=" + sortedFleets.length + ", sortedFleetIndex=" + sortedFleetIndex);

        if (sortedFleetIndex !== -1) {
            Crux.IconButton("icon-right-open", "key_right", "diplomacy")
                .grid(24.5 - 2.5 - 2.5, 0, 3, 3)
                .roost(fleetInspector);

            Crux.IconButton("icon-left-open", "key_left", "diplomacy")
                .grid(24.5 - 2.5 - 2.5 - 2.5, 0, 3, 3)
                .roost(fleetInspector);
        }

        Crux.Text(fleetKind, "rel pad12 col_black txt_center")
            .format({
                colourBox: universe.selectedFleet.colourBox,
                hyperlinkedAlias: universe.selectedFleet.hyperlinkedAlias})
            .roost(fleetInspector);

        npui.FleetStatus()
            .roost(fleetInspector);

        npui.FleetNav()
            .roost(fleetInspector);

        if (universe.selectedFleet.player === universe.player){
            npui.FleetPremium()
                .roost(fleetInspector);
        }

        npui.PlayerPanel(universe.selectedFleet.player, true)
            .roost(fleetInspector);

        fleetInspector.onLastFleet = function () {
            if (sortedFleetIndex !== -1) {
                ++sortedFleetIndex;
                if (sortedFleetIndex > sortedFleets.length - 1) {
                    sortedFleetIndex = 0;
                }
                npui.trigger("show_fleet_screen_uid", sortedFleets[sortedFleetIndex].uid);
            }
        };

        fleetInspector.onNextFleet = function () {
            if (sortedFleetIndex !== -1) {
                --sortedFleetIndex;
                if (sortedFleetIndex < 0) {
                    sortedFleetIndex = sortedFleets.length - 1;
                }
                npui.trigger("show_fleet_screen_uid", sortedFleets[sortedFleetIndex].uid);
            }
        };

        if (sortedFleetIndex !== -1) {
            fleetInspector.on("key_left", fleetInspector.onLastFleet);
            fleetInspector.on("key_right", fleetInspector.onNextFleet);
        }

        return fleetInspector;
    };

    NeptunesPride.np.trigger("map_refresh");
})();
2 Likes

Interesting. Nice to know that someone else is having the same problem. (I’ll set up a carrier loop, and then scanning the map later, I’ll notice there’s a break in the collection tree - somehow “Enable Looping” didn’t take, or got cancelled.)

This is handy; I like it.