// ==UserScript== // @author mrDinckleman // @id umbra@mrDinckleman // @name Umbra Deploy Challenge // @category Misc // @version 0.1.1.20191224.211839 // @description [2019-12-24-211839] Allow manual entry of portals deployed during Umbra Deploy Challenge. Use the 'highlighter-umbra' plugin to show the portals on the map, and 'sync' to share between multiple browsers or desktop/mobile. // @updateURL https://raw.githubusercontent.com/IITC-CE/Community-plugins/master/dist/mrDinckleman/umbra.meta.js // @downloadURL https://raw.githubusercontent.com/IITC-CE/Community-plugins/master/dist/mrDinckleman/umbra.user.js // @namespace https://github.com/mrDinckleman/iitc-plugins // @include https://intel.ingress.com/* // @match https://intel.ingress.com/* // @grant none // ==/UserScript== /* globals $ */ 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 ////////////////////////////////////////////////////////// var pluginName = 'umbra'; // Use own namespace for plugin window.plugin[pluginName] = function () {}; // Delay in ms window.plugin[pluginName].SYNC_DELAY = 5000; // Maps the JS property names to localStorage keys window.plugin[pluginName].FIELDS = { 'deployed': 'plugin-' + pluginName + '-data', 'updateQueue': 'plugin-' + pluginName + '-data-queue', 'updatingQueue': 'plugin-' + pluginName + '-data-updating-queue' }; window.plugin[pluginName].deployed = {}; window.plugin[pluginName].updateQueue = {}; window.plugin[pluginName].updatingQueue = {}; window.plugin[pluginName].enableSync = false; window.plugin[pluginName].disabledMessage = null; window.plugin[pluginName].contentHTML = null; window.plugin[pluginName].isHighlightActive = false; window.plugin[pluginName].onPortalDetailsUpdated = function () { var $preview = $('#portaldetails > .imgpreview'); if (typeof(Storage) === 'undefined') { $preview.after(window.plugin[pluginName].disabledMessage); return; } var guid = window.selectedPortal; $preview.after(window.plugin[pluginName].contentHTML); window.plugin[pluginName].updateCheckedAndHighlight(guid); }; window.plugin[pluginName].updateCheckedAndHighlight = function (guid) { if (guid === window.selectedPortal) { var deployCount = window.plugin[pluginName].deployed[guid] || 0; $('#umbra-deploy').val(deployCount); } if (window.plugin[pluginName].isHighlightActive) { if (window.portals[guid]) { window.setMarkerStyle(window.portals[guid], guid === window.selectedPortal); } } }; window.plugin[pluginName].updateDeployed = function (count, guid) { if (typeof guid === 'undefined') guid = window.selectedPortal; count = parseInt(count, 10); var deployCount = window.plugin[pluginName].deployed[guid] || 0; if (!deployCount) { window.plugin[pluginName].deployed[guid] = deployCount = 0; } // Nothing changed if (count === deployCount) return; window.plugin[pluginName].deployed[guid] = count; window.plugin[pluginName].updateCheckedAndHighlight(guid); window.plugin[pluginName].sync(guid); $('select.umbra-deploy[data-guid="' + guid + '"]').val(count); $('#dialog-' + pluginName + '-dialog').prev().find('.ui-dialog-title').text(window.plugin[pluginName].getModalTitle()); }; // Stores the given GUID for sync window.plugin[pluginName].sync = function (guid) { window.plugin[pluginName].updateQueue[guid] = true; window.plugin[pluginName].storeLocal('deployed'); window.plugin[pluginName].storeLocal('updateQueue'); window.plugin[pluginName].syncQueue(); }; // Sync the queue, but delay the actual sync to group a few updates in a single request window.plugin[pluginName].syncQueue = function () { if (!window.plugin[pluginName].enableSync) return; clearTimeout(window.plugin[pluginName].syncTimer); window.plugin[pluginName].syncTimer = setTimeout(function () { window.plugin[pluginName].syncTimer = null; $.extend(window.plugin[pluginName].updatingQueue, window.plugin[pluginName].updateQueue); window.plugin[pluginName].updateQueue = {}; window.plugin[pluginName].storeLocal('updatingQueue'); window.plugin[pluginName].storeLocal('updateQueue'); window.plugin.sync.updateMap('umbra', 'deployed', Object.keys(window.plugin[pluginName].updatingQueue)); }, window.plugin[pluginName].SYNC_DELAY); }; // Call after IITC and all plugin loaded window.plugin[pluginName].registerFieldForSyncing = function () { if (!window.plugin.sync) return; window.plugin.sync.registerMapForSync( 'umbra', 'deployed', window.plugin[pluginName].syncCallback, window.plugin[pluginName].syncInitialed ); }; // Call after local or remote change uploaded window.plugin[pluginName].syncCallback = function (inPluginName, fieldName, e, fullUpdated) { if (fieldName === 'deployed') { window.plugin[pluginName].storeLocal('deployed'); // All data is replaced if other client update the data during this client offline if (fullUpdated) { // A full update - update the selected portal sidebar if (window.selectedPortal) { window.plugin[pluginName].updateCheckedAndHighlight(window.selectedPortal); } // And also update all highlights, if needed if (window.plugin[pluginName].isHighlightActive) { window.resetHighlightedPortals(); } return; } if (!e) return; if (e.isLocal) { // Update pushed successfully, remove it from updatingQueue delete window.plugin[pluginName].updatingQueue[e.property]; } else { // Remote update delete window.plugin[pluginName].updateQueue[e.property]; window.plugin[pluginName].storeLocal('updateQueue'); window.plugin[pluginName].updateCheckedAndHighlight(e.property); } } }; // Syncing of the field is initialed, upload all queued update window.plugin[pluginName].syncInitialed = function (inPluginName, fieldName) { if (fieldName === 'deployed') { window.plugin[pluginName].enableSync = true; if (Object.keys(window.plugin[pluginName].updateQueue).length > 0) { window.plugin[pluginName].syncQueue(); } } }; window.plugin[pluginName].storeLocal = function (name) { var key = window.plugin[pluginName].FIELDS[name]; if (key === undefined) return; var value = window.plugin[pluginName][name]; if (typeof value !== 'undefined' && value !== null) { localStorage[key] = JSON.stringify(window.plugin[pluginName][name]); } else { localStorage.removeItem(key); } }; window.plugin[pluginName].loadLocal = function (name) { var key = window.plugin[pluginName].FIELDS[name]; if (key === undefined) return; if (localStorage[key] !== undefined) { window.plugin[pluginName][name] = JSON.parse(localStorage[key]); } }; /** * HIGHLIGHTER */ window.plugin[pluginName].highlighter = { highlight: function (data) { var guid = data.portal.options.ent[0]; var deployCount = window.plugin[pluginName].deployed[guid] || 0; var style = {}; switch (deployCount) { case 0: style.fillColor = hsl(0); // hsl(0,100%,50%) style.fillOpacity = 0.7; break; case 1: style.fillColor = hsl(1); style.fillOpacity = 0.7; break; case 2: style.fillColor = hsl(1.5); style.fillOpacity = 0.7; break; case 3: style.fillColor = hsl(2); style.fillOpacity = 0.7; break; case 4: style.fillColor = hsl(2.5); style.fillOpacity = 0.6; break; case 5: style.fillColor = hsl(3); style.fillOpacity = 0.6; break; case 6: style.fillColor = hsl(4); style.fillOpacity = 0.6; break; case 7: style.fillColor = hsl(6); style.fillOpacity = 0.8; break; case 8: // fully deployed - no highlights break; } data.portal.setStyle(style); function hsl(index) { // from 0 to 8 return 'hsl(' + (index / 8 * 120) + ', 100%, ' + (50 - index / 8 * 25) + '%)'; } }, setSelected: function (active) { window.plugin[pluginName].isHighlightActive = active; } }; window.plugin[pluginName].setupCSS = function () { $('