From 96edeeafb30f503bdc8f843ae83b6b75bf2151fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Celso=20Gonz=C3=A1lez?= Date: Tue, 31 May 2022 04:39:28 +0200 Subject: [PATCH] Initial release --- uniques-go.user.js | 126 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 uniques-go.user.js diff --git a/uniques-go.user.js b/uniques-go.user.js new file mode 100644 index 0000000..0c9f4d4 --- /dev/null +++ b/uniques-go.user.js @@ -0,0 +1,126 @@ +// ==UserScript== +// @id iitc-plugin-uniques-go@mitago +// @name IITC plugin: Uniques go data sender +// @category Misc +// @version 0.0.1 +// @namespace https://github.com/xificurk/iitc-plugins +// @updateURL https://raw.githubusercontent.com/xificurk/iitc-plugins/master/dist/portal-highlighter-uniques-opacity.mesta.js +// @downloadURL https://raw.githubusercontent.com/xificurk/iitc-plugins/master/dist/portal-highlighter-uniques-opacity.usser.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* +// @include https://*.ingress.com/mission/* +// @include http://*.ingress.com/mission/* +// @match https://*.ingress.com/mission/* +// @match http://*.ingress.com/mission/* +// @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 = '202200529.014500'; + plugin_info.pluginId = 'uniques-go'; + //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 + '
'; + } + }); + 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 }; + + window.plugin.uniquesgo.listPortals.push(obj); + }); + + return retval; + } + + var setup = function() { + if (window.useAppPanes()) { + //FIXME + app.addPane("plugin-portalslist", "Portals list", "ic_action_paste"); + } else { + $('#toolbox').append('Send portals'); + } + } + + //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); + + + + + + + \ No newline at end of file