Last active
August 12, 2023 15:46
-
-
Save nikhiljha/969e7cc6b9f61bdb7b6ac3fce940dc82 to your computer and use it in GitHub Desktop.
IITC Plugin to Export a list of all currently visible portals into Ingress Maxfield format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @id iitc-plugin-ingressmaxfield-exporter@nikhiljha | |
// @name IITC plugin: Ingress Maxfield Exporter | |
// @category Keys | |
// @author Nikhil Jha | |
// @version 0.0.9 | |
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion | |
// @description Exports portals currently in view as a list for use with Ingress Maxfield. | |
// @include https://www.ingress.com/intel* | |
// @include http://www.ingress.com/intel* | |
// @match https://www.ingress.com/intel* | |
// @match http://www.ingress.com/intel* | |
// @grant none | |
// ==/UserScript== | |
function wrapper() { | |
// Credit to github.com/OllieTerrance for writing the original code | |
// I just made it display something else | |
// Just in case IITC hasn't loaded yet. | |
if (typeof window.plugin !== "function") { | |
window.plugin = function() {}; | |
} | |
// base context for plugin | |
window.plugin.ingressdualmap = function() {}; | |
var self = window.plugin.ingressdualmap; | |
self.gen = function gen() { | |
var o = []; | |
for (var x in window.portals) { | |
var p = window.portals[x]; | |
var b = window.map.getBounds(); | |
// skip if not currently visible | |
if (p._latlng.lat < b._southWest.lat || p._latlng.lng < b._southWest.lng | |
|| p._latlng.lat > b._northEast.lat || p._latlng.lng > b._northEast.lng) continue; | |
var coord = p.getLatLng(); | |
var perma = 'http://ingress.com/intel?ll='+coord.lat+','+coord.lng+'&z=17&pll='+coord.lat+','+coord.lng; | |
o.push(p.options.data.title.replace(/\"/g, "\\\"") + "; " + perma); | |
} | |
var dialog = window.dialog({ | |
title: "Ingress Dual Map: CSV export", | |
html: '<span>Save the list below as a text file, then paste it into <a href="http://www.ingress-maxfield.com/">Ingress Maxfield.</a></span>' | |
+ '<textarea id="idmCSVExport" style="width: 600px; height: ' + ($(window).height() - 150) + 'px; margin-top: 5px;"></textarea>' | |
}).parent(); | |
$(".ui-dialog-buttonpane", dialog).remove(); | |
// width first, then centre | |
dialog.css("width", 630).css({ | |
"top": ($(window).height() - dialog.height()) / 2, | |
"left": ($(window).width() - dialog.width()) / 2 | |
}); | |
$("#idmCSVExport").val(o.join("\n")); | |
return dialog; | |
}; | |
// setup function called by IITC | |
self.setup = function init() { | |
// add controls to toolbox | |
var link = $("<a onclick=\"window.plugin.ingressdualmap.gen();\" title=\"Generate a list of portals and links for use with Ingress Maxfield.\">Maxfield Export</a>"); | |
$("#toolbox").append(link); | |
// delete setup to ensure init can't be run again | |
delete self.setup; | |
}; | |
// IITC plugin setup | |
if (window.iitcLoaded && typeof self.setup === "function") { | |
self.setup(); | |
} else if (window.bootPlugins) { | |
window.bootPlugins.push(self.setup); | |
} else { | |
window.bootPlugins = [self.setup]; | |
} | |
} | |
// Inject the plugin | |
var script = document.createElement("script"); | |
script.appendChild(document.createTextNode("(" + wrapper + ")();")); | |
(document.body || document.head || document.documentElement).appendChild(script); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment