// ==UserScript== // @id iitc-plugin-offle // @name IITC plugin: offle // @category Misc // @version 0.7.2 // @namespace https://github.com/vrabcak/iitc-offle // @description Offle // @include https://*.ingress.com/intel* // @include http://*.ingress.com/intel* // @match https://*.ingress.com/intel* // @match http://*.ingress.com/intel* // @grant none // @require https://github.com/mozilla/localForage/releases/download/1.2.10/localforage.js // ==/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 START //////////////////////////////////////////////////////// // use own namespace for plugin window.plugin.offle = function () {}; var offle = window.plugin.offle; offle.portalDb = {}; offle.lastAddedDb = {}; offle.symbol = '•'; offle.symbolWithMission = '◉'; offle.maxVisibleCount = 2000; // Use portal add event to save it to db offle.portalAdded = function (data) { offle.addPortal( data.portal.options.guid, data.portal.options.data.title, data.portal.getLatLng(), data.portal.options.data.mission ); }; // Always update portal data if displayed in sidebar (to handle e.g. moved portals) offle.portalDetailsUpdated = function (data) { var guid = data.portal.options.guid, name = data.portal.options.data.title; if (name) { //update data only with portals with full details offle.portalDb[guid] = data.portal.getLatLng(); offle.portalDb[guid].name = data.portal.options.data.title; offle.portalDb[guid].mission = data.portal.options.data.mission; offle.renderVisiblePortals(); localforage.setItem('portalDb', offle.portalDb); } }; offle.addPortal = function (guid, name, latLng, mission) { var notInDb = guid && !(guid in offle.portalDb); var newName = name && offle.portalDb[guid] && !offle.portalDb[guid].name; //console.log("AddPortal ", guid," ",name, "::", notInDb, " ", newName); if (notInDb || newName) { //add to last added list only new portals or update already displayed guid with name if (notInDb || (newName && (guid in offle.lastAddedDb))) { offle.lastAddedDb[guid] = { name: name || guid, latLng: latLng, unique: false }; if (!(window.plugin.uniques && (guid in window.plugin.uniques.uniques))) { offle.lastAddedDb[guid].unique = true; } } offle.portalDb[guid] = latLng; offle.portalDb[guid].name = name; offle.portalDb[guid].mission = mission; offle.dirtyDb = true; //mark Db dirty to by stored on mapDataRefreshEnd offle.renderPortal(guid); offle.updatePortalCounter(); offle.updateLACounter(); offle.updateLAList(); } }; offle.renderPortal = function (guid) { var portalMarker, uniqueInfo, iconCSSClass = 'offle-marker'; if (window.plugin.uniques) { uniqueInfo = window.plugin.uniques.uniques[guid]; } if (uniqueInfo) { if (uniqueInfo.visited) { iconCSSClass += ' offle-marker-visited-color'; } if (uniqueInfo.captured) { iconCSSClass += ' offle-marker-captured-color'; } } portalMarker = L.marker(offle.portalDb[guid], { icon: L.divIcon({ className: iconCSSClass, iconAnchor: [15, 23], iconSize: [30, 30], html: offle.portalDb[guid].mission ? offle.symbolWithMission : offle.symbol }), name: offle.portalDb[guid].name, title: offle.portalDb[guid].name || '' }); portalMarker.on('click', function () { window.renderPortalDetails(guid); }); portalMarker.addTo(offle.portalLayerGroup); if (window.plugin.keys) { var keyCount = window.plugin.keys.keys[guid]; if (keyCount > 0) { var keyMarker = L.marker(offle.portalDb[guid], { icon: L.divIcon({ className: 'offle-key', iconAnchor: [6, 7], iconSize: [12, 10], html: keyCount }), guid: guid }); keyMarker.addTo(offle.keyLayerGroup); } } }; offle.clearLayer = function () { offle.portalLayerGroup.clearLayers(); offle.keyLayerGroup.clearLayers(); }; offle.mapDataRefreshEnd = function () { if (offle.dirtyDb) { //console.log("Storing new portals to localStorage"); localforage.setItem('portalDb', offle.portalDb); } offle.dirtyDb = false; }; offle.setupLayer = function () { offle.portalLayerGroup = new L.LayerGroup(); window.addLayerGroup('offlePortals', offle.portalLayerGroup, false); offle.keyLayerGroup = new L.LayerGroup(); window.addLayerGroup('offleKeys', offle.keyLayerGroup, false); }; offle.setupCSS = function () { $('