Created
February 6, 2017 21:19
-
-
Save MTRNord/8be504c66c68ae34b777d6a827861b5e to your computer and use it in GitHub Desktop.
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-portal-export | |
// @name IITC plugin: Export visible portals to JSON | |
// @category Info | |
// @version 0.1.0.@@DATETIMEVERSION@@ | |
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion | |
// @updateURL @@UPDATEURL@@ | |
// @downloadURL @@DOWNLOADURL@@ | |
// @description [@@BUILDNAME@@-@@BUILDDATE@@] Display a list of all localized portals by level and faction. | |
// @include https://*.ingress.com/intel* | |
// @include http://*.ingress.com/intel* | |
// @match https://*.ingress.com/intel* | |
// @match http://*.ingress.com/intel* | |
// @include https://*.ingress.com/mission/* | |
// @include http://*.ingress.com/mission/* | |
// @match https://*.ingress.com/mission/* | |
// @match http://*.ingress.com/mission/* | |
// @grant none | |
// ==/UserScript== | |
// PLUGIN START //////////////////////////////////////////////////////// | |
// use own namespace for plugin | |
window.plugin.portalexport = {}; | |
window.plugin.portalexport.export = function () { | |
var data = [], | |
displayBounds = map.getBounds(); | |
$.each(window.portals, function(i, portal) { | |
var loc = portal.getLatLng(); | |
if(!displayBounds.contains(loc)) return true; | |
data.push({ | |
"guid": portal.options.guid, | |
"location": { | |
"lat": loc.lat, | |
"lng": loc.lng | |
} | |
}); | |
}); | |
var json = JSON.stringify(data, null, 2); | |
console.log("Exported: " + data.length, json); | |
downloadFile(json); | |
window.exportedPortals = json; | |
} | |
var cleanUp = function(a) { | |
a.textContent = 'Downloaded'; | |
a.dataset.disabled = true; | |
// Need a small delay for the revokeObjectURL to work properly. | |
setTimeout(function() { | |
window.URL.revokeObjectURL(a.href); | |
}, 1500); | |
}; | |
var downloadFile = function(json) { | |
var container = document.querySelector('#toolbox'); | |
const MIME_TYPE = 'application/javascript'; | |
var output = container.querySelector('output'); | |
window.URL = window.webkitURL || window.URL; | |
var bb = new Blob([json], {type: MIME_TYPE}); | |
var a = document.createElement('a'); | |
a.download = "portals.json"; | |
a.href = window.URL.createObjectURL(bb); | |
a.textContent = 'Download ready'; | |
a.dataset.downloadurl = [MIME_TYPE, a.download, a.href].join(':'); | |
a.draggable = true; // Don't really need, but good practice. | |
a.classList.add('dragout'); | |
output.appendChild(a); | |
a.onclick = function(e) { | |
if ('disabled' in this.dataset) { | |
return false; | |
} | |
cleanUp(this); | |
}; | |
}; | |
var setup = function() { | |
$('#toolbox').append(' <a onclick="window.plugin.portalexport.export()" title="Export visible portals to JSON">To JSON</a> <output></output>'); | |
}; | |
if(!window.bootPlugins) { | |
window.bootPlugins = []; | |
} | |
window.bootPlugins.push(setup); | |
if(window.iitcLoaded && typeof setup === 'function') { | |
setup(); | |
} | |
// PLUGIN END ////////////////////////////////////////////////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment