// ==UserScript== // @id iitc-plugin-keys-on-map@xelio // @name IITC plugin: Keys on map // @category Keys // @version 0.2.1.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @updateURL @@UPDATEURL@@ // @downloadURL @@DOWNLOADURL@@ // @description [@@BUILDNAME@@-@@BUILDDATE@@] Show the manually entered key counts from the 'keys' plugin on the map. // @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== @@PLUGINSTART@@ // PLUGIN START //////////////////////////////////////////////////////// // use own namespace for plugin window.plugin.keysOnMap = function() {}; window.plugin.keysOnMap.keyLayers = {}; // Use portal add and remove event to control render of keys window.plugin.keysOnMap.portalAdded = function(data) { // Disable if Plugin Keys is not there if(!plugin.keys) { plugin.keysOnMap.disableMessage(); return; } data.portal.on('add', function() { plugin.keysOnMap.renderKey(this.options.guid, this.getLatLng()); }); data.portal.on('remove', function() { plugin.keysOnMap.removeKey(this.options.guid); }); } window.plugin.keysOnMap.keyUpdate = function(data) { // Disable if Plugin Keys is not there if(!plugin.keys) { plugin.keysOnMap.disableMessage(); return; } var portal = window.portals[data.guid]; if(!portal) return; var latLng = portal.getLatLng(); plugin.keysOnMap.renderKey(data.guid, latLng) } window.plugin.keysOnMap.refreshAllKeys = function() { plugin.keysOnMap.keyLayerGroup.clearLayers(); $.each(plugin.keys.keys, function(key, count) { plugin.keysOnMap.keyUpdate({guid: key}); }); } window.plugin.keysOnMap.renderKey = function(guid,latLng) { plugin.keysOnMap.removeKey(guid); var keyCount = plugin.keys.keys[guid]; if (keyCount > 0) { var key = L.marker(latLng, { icon: L.divIcon({ className: 'plugin-keys-on-map-key', iconAnchor: [6,7], iconSize: [12,10], html: keyCount }), guid: guid }); plugin.keysOnMap.keyLayers[guid] = key; key.addTo(plugin.keysOnMap.keyLayerGroup); } } window.plugin.keysOnMap.removeKey = function(guid) { var previousLayer = plugin.keysOnMap.keyLayers[guid]; if(previousLayer) { plugin.keysOnMap.keyLayerGroup.removeLayer(previousLayer); delete plugin.keysOnMap.keyLayers[guid]; } } window.plugin.keysOnMap.disableMessage = function() { if(!plugin.keysOnMap.messageShown) { alert('Plugin "Keys On Map" need plugin "Keys" to run!'); plugin.keysOnMap.messageShown = true; } } window.plugin.keysOnMap.setupCSS = function() { $("