From 286331652438875fe7617ecdfbce5ce7335438a7 Mon Sep 17 00:00:00 2001 From: YenkyK Date: Mon, 25 Mar 2013 12:52:57 +0100 Subject: [PATCH] Added new plugin portal-counts --- plugins/portal-counts.user.js | 138 ++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 plugins/portal-counts.user.js diff --git a/plugins/portal-counts.user.js b/plugins/portal-counts.user.js new file mode 100644 index 00000000..c2b366e0 --- /dev/null +++ b/plugins/portal-counts.user.js @@ -0,0 +1,138 @@ +// ==UserScript== +// @id iitc-plugin-portals-count@yenky +// @name IITC plugin: show count list of portals by level +// @version 0.0.1.20130325.095313 +// @namespace https://github.com/jonatkins/ingress-intel-total-conversion +// @updateURL https://secure.jonatkins.com/iitc/release/plugins/portals-count.meta.js +// @downloadURL https://secure.jonatkins.com/iitc/release/plugins/portals-count.user.js +// @description [jonatkins-2013-03-25-095313] Display a list of all localized portals by level +// @include https://www.ingress.com/intel* +// @include http://www.ingress.com/intel* +// @match https://www.ingress.com/intel* +// @match http://www.ingress.com/intel* +// ==/UserScript== + +/* whatsnew +* 0.0.1 : initial release, show count of portals +* todo : +*/ + +function wrapper() { +// ensure plugin framework is there, even if iitc is not yet loaded +if(typeof window.plugin !== 'function') window.plugin = function() {}; + +// PLUGIN START //////////////////////////////////////////////////////// + +// use own namespace for plugin +window.plugin.portalcounts = function() {}; + +window.plugin.portalcounts.enlP = 0; +window.plugin.portalcounts.resP = 0; +window.plugin.portalcounts.neuP = 0; + +//count portals for each level avalaible on the map +window.plugin.portalcounts.getPortals = function(){ + //console.log('** getPortals'); + var retval=false; + + window.plugin.portalcounts.PortalsEnl = new Array(); + window.plugin.portalcounts.PortalsEnl[1] = 0; + window.plugin.portalcounts.PortalsEnl[2] = 0; + window.plugin.portalcounts.PortalsEnl[3] = 0; + window.plugin.portalcounts.PortalsEnl[4] = 0; + window.plugin.portalcounts.PortalsEnl[5] = 0; + window.plugin.portalcounts.PortalsEnl[6] = 0; + window.plugin.portalcounts.PortalsEnl[7] = 0; + window.plugin.portalcounts.PortalsEnl[8] = 0; + window.plugin.portalcounts.PortalsRes= new Array(); + window.plugin.portalcounts.PortalsRes[1] = 0; + window.plugin.portalcounts.PortalsRes[2] = 0; + window.plugin.portalcounts.PortalsRes[3] = 0; + window.plugin.portalcounts.PortalsRes[4] = 0; + window.plugin.portalcounts.PortalsRes[5] = 0; + window.plugin.portalcounts.PortalsRes[6] = 0; + window.plugin.portalcounts.PortalsRes[7] = 0; + window.plugin.portalcounts.PortalsRes[8] = 0; + //get portals informations from IITC + $.each(window.portals, function(i, portal) { + + retval=true; + var d = portal.options.details; + var team = portal.options.team; + var level = getPortalLevel(d).toFixed(); + switch (team){ + case 1 : + window.plugin.portalcounts.resP++; + window.plugin.portalcounts.PortalsRes[level]++; + break; + case 2 : + window.plugin.portalcounts.enlP++; + window.plugin.portalcounts.PortalsEnl[level]++; + break; + default: + window.plugin.portalcounts.neuP++; + break; + } + + }); + var counts = ''; + if(retval) { + counts += ''; + for (level in window.plugin.portalcounts.PortalsEnl) { + counts += ''; + } + counts += ''; + counts += ''; + for (level in window.plugin.portalcounts.PortalsRes) { + counts += ''; + } + counts += ''; + counts += ''; + } else + counts += ''; + counts += '
Enlightment: '+window.plugin.portalcounts.enlP+' Portal(s)
Level '+level+''+window.plugin.portalcounts.PortalsEnl[level]+'
 
Resistance: '+window.plugin.portalcounts.resP+' Portal(s)
Level '+level+''+window.plugin.portalcounts.PortalsRes[level]+'
 
Neutral: '+window.plugin.portalcounts.neuP+' Portal(s)
No Portals in range !
'; + counts += '
Thanks to @teo96 for his plugin as base for me. Work done by @yenky. Be enlightened!
'; + alert('
'+counts+'
'); +} + +var setup = function() { + $('body').append(''); + $('#toolbox').append('Portalcounts'); + $('head').append(''); +} + +// PLUGIN END ////////////////////////////////////////////////////////// + +if(window.iitcLoaded && typeof setup === 'function') { + setup(); +} else { + if(window.bootPlugins) + window.bootPlugins.push(setup); + else + window.bootPlugins = [setup]; +} +} // wrapper end +// inject code into site context +var script = document.createElement('script'); +script.appendChild(document.createTextNode('('+ wrapper +')();')); +(document.body || document.head || document.documentElement).appendChild(script);