Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @id iitc-plugin-ingressdualmap-exporter@OllieTerrance
// @name IITC plugin: Ingress Dual Map Exporter
// @category Keys
// @version 0.0.0.1
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @description Exports portals currently in view as a CSV list for use with Ingress Dual Map.
// @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() {
// in case IITC is not available yet, define the base plugin object
if (typeof window.plugin !== "function") {
window.plugin = function() {};
}
// base context for plugin
window.plugin.ingressdualmap = function() {};
var self = window.plugin.ingressdualmap;
// custom dialog wrapper with more flexibility
self.gen = function gen() {
var o = [];
var displayBounds = map.getBounds();
for (var x in window.portals) {
var p = window.portals[x];
// skip off-screen portals
if(!displayBounds.contains(p.getLatLng())) continue;
o.push("\"" + p.options.data.title.replace(/\"/g, "\"\"") + "\",,," + p._latlng.lat + "," + p._latlng.lng);
}
var dialog = window.dialog({
title: "CSV export",
// body must be wrapped in an outer tag (e.g. <div>content</div>)
html: '<span>Paste data into <a href="http://www.convertcsv.com/csv-to-kml.htm">http://www.convertcsv.com/csv-to-kml.htm</a> and save result as KML file.</span>'
+ '<textarea id="idmCSVExport" rows="30" style="width: 100%;"></textarea>'
}).parent();
$(".ui-dialog-buttonpane", dialog).remove();
dialog.css("width", "600px")
.css("top", ($(window).height() - dialog.height()) / 2)
.css("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 CSV list of portals and locations..\">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 plugin into page
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