// ==UserScript== // @id iitc-plugin-Dynamic-Scoreboard@Costaspap // @name IITC plugin: Create a local scoreboard // @category Info // @version 0.1.0.20140524.214738 // @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @updateURL https://secure.jonatkins.com/iitc/release/total-conversion-build.meta.js // @downloadURL https://secure.jonatkins.com/iitc/release/total-conversion-build.user.js // @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== // A plug in by Costaspap and harisbitsakou 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 = 'jonatkins'; plugin_info.dateTimeVersion = '20140524.214738'; plugin_info.pluginId = 'Dynamic Scoreboard'; //END PLUGIN AUTHORS NOTE // PLUGIN START // // use own namespace for plugin window.plugin.scoreboard = function() {}; //gets data of all the visible portals on the screen window.plugin.scoreboard.getPortals = function() { var retval=false; var displayBounds = map.getBounds(); window.plugin.scoreboard.enlP = 0; window.plugin.scoreboard.resP = 0; window.plugin.scoreboard.enlEightLevelP = 0; window.plugin.scoreboard.resEightLevelP = 0; window.plugin.scoreboard.enlPorLevels = 0; window.plugin.scoreboard.resPorLevels = 0; window.plugin.scoreboard.maxEnl=0; window.plugin.scoreboard.maxRes=0; window.plugin.scoreboard.healthEnl = 0; window.plugin.scoreboard.healthRes = 0; //get all portals on screen $.each(window.portals, function(i, portal) { // eliminate offscreen portals (selected, and in padding) if(!displayBounds.contains(portal.getLatLng())) return true; //if there are any portals return true retval=true; //variable that contains portal data var d = portal.options.data; //variable that contains each portal's team value var teamN = portal.options.team; switch (teamN) { case TEAM_RES: //if the portal is captured by the resistance,increase each counter's value for resistance counters window.plugin.scoreboard.healthRes += d.health; window.plugin.scoreboard.resP++; window.plugin.scoreboard.resPorLevels = window.plugin.scoreboard.resPorLevels + portal.options.level; if(portal.options.level===8){window.plugin.scoreboard.resEightLevelP++;} if(portal.options.level>window.plugin.scoreboard.maxRes){window.plugin.scoreboard.maxRes = portal.options.level;} break; case TEAM_ENL: //if the portal is captured by the enlightened,increase each counter's value for enlightened counters window.plugin.scoreboard.healthEnl += d.health; window.plugin.scoreboard.enlP++; window.plugin.scoreboard.enlPorLevels = window.plugin.scoreboard.enlPorLevels + portal.options.level; if(portal.options.level===8){window.plugin.scoreboard.enlEightLevelP++;} if(portal.options.level>window.plugin.scoreboard.maxEnl){window.plugin.scoreboard.maxEnl = portal.options.level;} break; } }); return retval; } //---- function that gets all visible enlightened links on screen window.plugin.scoreboard.getEnlLinks = function() { var displayBounds = map.getBounds(); window.plugin.scoreboard.enlL=0; // now every link that starts/ends at a point on screen $.each(window.links, function(guid, link) { // only consider links that start/end on-screen var points = link.getLatLngs(); if (displayBounds.contains(points[0]) || displayBounds.contains(points[1])) { if (link.options.team == TEAM_ENL) { window.plugin.scoreboard.enlL++; } } }); return window.plugin.scoreboard.enlL; } //----function that gets all visible resistance links on screen window.plugin.scoreboard.getResLinks = function() { var displayBounds = map.getBounds(); window.plugin.scoreboard.resL=0; // now every link that starts/ends at a point on screen $.each(window.links, function(guid, link) { // only consider links that start/end on-screen var points = link.getLatLngs(); if (displayBounds.contains(points[0]) || displayBounds.contains(points[1])) {// boroume na kanoume ta 2 if ena if (link.options.team == TEAM_RES) { window.plugin.scoreboard.resL++; } } }); return window.plugin.scoreboard.resL; } //----function that gets all visible enlightened fields on screen window.plugin.scoreboard.getEnlFields = function() { var displayBounds = map.getBounds(); window.plugin.scoreboard.enlF=0; // and now all fields that have a vertex on screen $.each(window.fields, function(guid, field) { // only consider fields with at least one vertex on screen var points = field.getLatLngs(); if (displayBounds.contains(points[0]) || displayBounds.contains(points[1]) || displayBounds.contains(points[2])) { if (field.options.team == TEAM_ENL) { window.plugin.scoreboard.enlF++; } } }); return window.plugin.scoreboard.enlF; } //----function that gets all visible resistance fields on screen window.plugin.scoreboard.getResFields = function() { var displayBounds = map.getBounds(); window.plugin.scoreboard.resF=0; // and now all fields that have a vertex on screen $.each(window.fields, function(guid, field) { // only consider fields with at least one vertex on screen var points = field.getLatLngs(); if (displayBounds.contains(points[0]) || displayBounds.contains(points[1]) || displayBounds.contains(points[2])) { if (field.options.team == TEAM_RES) { window.plugin.scoreboard.resF++; } } }); return window.plugin.scoreboard.resF; } // A function that creates the html code for the scoreboard table window.plugin.scoreboard.portalTable = function() { // html variable declaration var html = ""; // Create the header html += '
Metrics | ' + 'Enlightened | ' + 'Resistance | ' + '
---|---|---|
Number of Portals | '+'' +window.plugin.scoreboard.enlP+' | '+''+window.plugin.scoreboard.resP+' |
Average Portal Level | '+'' +avgEnl+' | '+''+avgRes+' |
Number of Level 8 Portals | '+'' +window.plugin.scoreboard.enlEightLevelP+' | '+''+window.plugin.scoreboard.resEightLevelP+' |
Max Portal Level | '+'' +window.plugin.scoreboard.maxEnl+' | '+''+window.plugin.scoreboard.maxRes+' |
Number of Links | '+'' +enlCountOfLinks+' | '+''+resCountOfLinks+' |
Number of Fields | '+'' +enlCountOfFields+' | '+''+resCountOfFields+' |
Average portal Health | '+'' +avgHealthEnl+'% | '+''+avgHealthRes+'% |