diff --git a/plugins/portal-defense.user.js b/plugins/portal-defense.user.js index 0566a294..3d1f30fb 100644 --- a/plugins/portal-defense.user.js +++ b/plugins/portal-defense.user.js @@ -12,163 +12,3 @@ // @match https://www.ingress.com/intel* // @match http://www.ingress.com/intel* // ==/UserScript== -<<<<<<< HEAD - -@@PLUGINSTART@@ - -// PLUGIN START //////////////////////////////////////////////////////// - -// use own namespace for plugin -window.plugin.portalDefense = function() {}; - -window.plugin.portalDefense.MIN_MAP_ZOOM = 15; -window.plugin.portalDefense.DETAIL_MAP_ZOOM = 17; -window.plugin.portalDefense.DisplayEnum = { - OFF : 0, - SIMPLE : 1, - DETAIL : 2 -}; - -window.plugin.portalDefense.regionLayers = {}; - -// Use portal add and remove event to control render of regions -window.plugin.portalDefense.portalAdded = function(data) { - data.portal.on('add', function() { - plugin.portalDefense.renderAttackRegion(this); - }); - - data.portal.on('remove', function() { - plugin.portalDefense.removeAttackRegion(this); - }); -} - -window.plugin.portalDefense.getDisplay = function() { - if (map.getZoom() >= window.plugin.portalDefense.DETAIL_MAP_ZOOM) { - return window.plugin.portalDefense.DisplayEnum.DETAIL; - } else if (map.getZoom() >= window.plugin.portalDefense.MIN_MAP_ZOOM) { - return window.plugin.portalDefense.DisplayEnum.SIMPLE; - } - return window.plugin.portalDefense.DisplayEnum.OFF; -} - -window.plugin.portalDefense.renderAttackRegion = function(portal) { - plugin.portalDefense.removeAttackRegion(portal); - if (window.plugin.portalDefense.currentDisplay == window.plugin.portalDefense.DisplayEnum.OFF) return; - - plugin.portalDefense.regionLayers[portal.options.guid] = []; - var defense = window.getPortalMitigationDetails(portal.options.details); - if (defense.total) { - var display = defense.total; - if (window.plugin.portalDefense.currentDisplay == window.plugin.portalDefense.DisplayEnum.DETAIL) { - if (defense.shields) { - display += "
"+"\u2297"+defense.shields; - } - if(defense.links) { - display += "
"+"\u21b1"+defense.links; - } - } - var region = L.marker(portal.getLatLng(), { - icon: L.divIcon({ - className: 'plugin-iitc-defense', - clickable: false, - iconAnchor: [-10,10], - html: "
"+display+"
" - }), - guid: portal.options.guid - }); - plugin.portalDefense.regionLayers[portal.options.guid].push(region); - region.addTo(plugin.portalDefense.regionLayerGroup); - } -} - -window.plugin.portalDefense.reload = function() { - $.each(window.portals, function(ind, portal) { - // only render mitigation details for portals added to the map - if (portal._map) { - window.plugin.portalDefense.renderAttackRegion(portal) - } - }); -} - -window.plugin.portalDefense.removeAttackRegion = function(portal) { - var previousLayers = plugin.portalDefense.regionLayers[portal.options.guid]; - if (previousLayers) { - for (var i = 0; i < previousLayers.length; i++) { - plugin.portalDefense.regionLayerGroup.removeLayer(previousLayers[i]); - } - delete plugin.portalDefense.regionLayers[portal.options.guid]; - } -} - -window.plugin.portalDefense.regions = {} - -window.plugin.portalDefense.showOrHide = function() { - var ctrl = $('.leaflet-control-layers-selector + span:contains("Portal Defense")').parent(); - var display = window.plugin.portalDefense.getDisplay(); - if (display != window.plugin.portalDefense.DisplayEnum.OFF) { - // show the layer - if(!window.plugin.portalDefense.regionLayerGroup.hasLayer(window.plugin.portalDefense.defenseLayerGroup)) { - window.plugin.portalDefense.regionLayerGroup.addLayer(window.plugin.portalDefense.defenseLayerGroup); - } - ctrl.removeClass('disabled').attr('title', ''); - } else { - // hide the layer - if(window.plugin.portalDefense.regionLayerGroup.hasLayer(window.plugin.portalDefense.defenseLayerGroup)) { - window.plugin.portalDefense.regionLayerGroup.removeLayer(window.plugin.portalDefense.defenseLayerGroup); - } - ctrl.addClass('disabled').attr('title', 'Zoom in to show those.'); - } - if (window.plugin.portalDefense.currentDisplay != display) { - window.plugin.portalDefense.currentDisplay = display; - window.plugin.portalDefense.reload() - } -} - -var setup = function() { - $('#toolbox').append(' Reload Defense'); - $("