uniques-go-userscript/uniques-go.user.js

130 lines
4.7 KiB
JavaScript

// ==UserScript==
// @id iitc-plugin-uniques-go@mitago
// @name IITC plugin: Uniques go data sender
// @category Misc
// @version 0.0.4
// @namespace https://git.mitago.net/ingress/uniques-go-userscript
// @updateURL https://git.mitago.net/ingress/uniques-go-userscript/raw/branch/master/uniques-go.user.js
// @downloadURL https://git.mitago.net/ingress/uniques-go-userscript/raw/branch/master/uniques-go.user.js
// @description Uniques go data sender
// @include https://intel.ingress.com/*
// @include http://intel.ingress.com/*
// @match https://intel.ingress.com/*
// @match http://intel.ingress.com/*
// @include https://*.ingress.com/intel*
// @include http://*.ingress.com/intel*
// @match https://*.ingress.com/intel*
// @match http://*.ingress.com/intel*
// @grant none
// ==/UserScript==
function wrapper(plugin_info) {
// ensure plugin framework is there, even if iitc is not yet loaded
if(typeof window.plugin !== 'function') window.plugin = function() {};
//PLUGIN AUTHORS: writing a plugin outside of the IITC build environment? if so, delete these lines!!
//(leaving them in place might break the 'About IITC' page or break update checks)
plugin_info.buildName = 'mitago';
plugin_info.dateTimeVersion = '202200603.130500';
plugin_info.pluginId = 'uniquesgo';
//END PLUGIN AUTHORS NOTE
//PLUGIN START ////////////////////////////////////////////////////////
//use own namespace for plugin
window.plugin.uniquesgo = function () {};
window.plugin.uniquesgo.sendPL = function() {
if (window.plugin.uniquesgo.getPortals()) {
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
dataType: "json",
url: `https://uniq.mitago.net/import/`,
data: JSON.stringify(window.plugin.uniquesgo.listPortals),
success: window.plugin.uniquesgo.AjaxOK
});
} else {
alert('Espera a cargar todo');
};
}
window.plugin.uniquesgo.AjaxOK = function (result) {
let a = '';
$.each(result, function(i, val) {
if (val > 0) {
a += i + ': ' + val + '<br/>';
}
});
alert(a);
}
window.plugin.uniquesgo.getPortals = function() {
var retval=false;
var displayBounds = map.getBounds();
window.plugin.uniquesgo.listPortals = [];
$.each(window.portals, function(i, portal) {
// eliminate offscreen portals (selected, and in padding)
if(!displayBounds.contains(portal.getLatLng())) return true;
if (!('title' in portal.options.data)) {
return true; // filter out placeholder portals
}
retval=true;
//console.debug(portal);
var obj = { 'guid': portal.options.guid, 'title': portal.options.data.title, 'history': portal.options.data.history._raw, 'position': portal._latlng, 'faction': portal.options.data.team };
window.plugin.uniquesgo.listPortals.push(obj);
});
return retval;
}
window.plugin.uniquesgo.onPaneChanged = function(pane) {
if(pane === "plugin-uniquesgo")
window.plugin.uniquesgo.sendPL();
else
$("#uniquesgo").remove()
};
var setup = function() {
if (window.useAppPanes()) {
//FIXME
app.addPane("plugin-uniquesgo", "Send portals to mitago", "ic_action_paste");
addHook("paneChanged", window.plugin.uniquesgo.onPaneChanged);
} else {
$('#toolbox').append('<a onclick="window.plugin.uniquesgo.sendPL()" title="Sends the portal list to mitago.net [t]" accesskey="t">Send portals</a>');
}
}
//PLUGIN END //////////////////////////////////////////////////////////
setup.info = plugin_info; //add the script info data to the function as a property
if(!window.bootPlugins) window.bootPlugins = [];
window.bootPlugins.push(setup);
// if IITC has already booted, immediately run the 'setup' function
if(window.iitcLoaded && typeof setup === 'function') setup();
} // wrapper end
// inject code into site context
var script = document.createElement('script');
var info = {};
if (typeof GM_info !== 'undefined' && GM_info && GM_info.script) info.script = { version: GM_info.script.version, name: GM_info.script.name, description: GM_info.script.description };
script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));
(document.body || document.head || document.documentElement).appendChild(script);