diff --git a/plugins/keys.css b/plugins/keys.css new file mode 100644 index 00000000..dcb5b3b1 --- /dev/null +++ b/plugins/keys.css @@ -0,0 +1,58 @@ +#keys-content-outer { + display: table; + width: 100%; + height: 26px; + text-align: center; +} + +#keys-content-outer > div{ + display: inline-block; + vertical-align: middle; + margin: 6px 3px 1px 3px; +} + +#keys-label { + padding: 0 4px; +} + +#keys-add { +} + +#keys-count { + width: 26px; + height: 18px !important; + border: 1px solid; + text-align: center; +} + +#keys-subtract { +} + +.keys-button { + position:relative; + width: 16px; + height: 16px !important; +} + +.keys-button > div { + background-color: rgb(32, 168, 177); + position: absolute; +} + +.keys-button-minus { + width: 100%; + height: 4px; + top: 6px; +} + +.keys-button-plus-h { + width: 100%; + height: 4px; + top: 6px; +} + +.keys-button-plus-v { + width: 4px; + height: 100%; + left: 6px; +} diff --git a/plugins/keys.user.js b/plugins/keys.user.js new file mode 100644 index 00000000..40de85c7 --- /dev/null +++ b/plugins/keys.user.js @@ -0,0 +1,123 @@ +// ==UserScript== +// @id iitc-plugin-keys@xelio +// @name IITC plugin: Keys +// @version 0.1.0.@@DATETIMEVERSION@@ +// @namespace https://github.com/jonatkins/ingress-intel-total-conversion +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ +// @description [@@BUILDNAME@@-@@BUILDDATE@@] Store portal keys +// @include https://www.ingress.com/intel* +// @include http://www.ingress.com/intel* +// @match https://www.ingress.com/intel* +// @match http://www.ingress.com/intel* +// ==/UserScript== + +function wrapper() { +// 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.keys = function() {}; + +window.plugin.keys.LOCAL_STORAGE_KEY = 'plugin-keys-data'; + +window.plugin.keys.keys = {}; +window.plugin.keys.disabledMessage; +window.plugin.keys.contentHTML; + +window.plugin.keys.displayKeys = function() { + if(typeof(Storage) === "undefined") { + $('#portaldetails > .imgpreview').after(plugin.keys.disabledMessage); + return; + } + + $('#portaldetails > .imgpreview').after(plugin.keys.contentHTML); + plugin.keys.updateDisplay(); +} + +window.plugin.keys.updateDisplay = function() { + var guid = window.selectedPortal; + var count = plugin.keys.keys[guid] || 0; + $('#keys-count').html(count); +} + +window.plugin.keys.addKey = function(addCount) { + var guid = window.selectedPortal; + var oldCount = plugin.keys.keys[guid]; + var newCount = Math.max((oldCount || 0) + addCount, 0); + if(oldCount !== newCount) { + if(newCount === 0) { + delete plugin.keys.keys[guid]; + } else { + plugin.keys.keys[guid] = newCount; + } + plugin.keys.storeKeys(); + plugin.keys.updateDisplay(); + window.runHooks('pluginKeysUpdateKey', {guid: guid, count: newCount}); + } +} + +window.plugin.keys.storeKeys = function() { + var keysObject = {keys: plugin.keys.keys}; + var keysObjectJSON = JSON.stringify(keysObject); + console.log(keysObjectJSON); + localStorage[plugin.keys.LOCAL_STORAGE_KEY] = keysObjectJSON; +} + +window.plugin.keys.loadKeys = function() { + var keysObjectJSON = localStorage[plugin.keys.LOCAL_STORAGE_KEY] + var keysObject = JSON.parse(keysObjectJSON); + plugin.keys.keys = keysObject.keys; +} + +window.plugin.keys.setupCSS = function() { + $("