Merge pull request #74 from Xelio/plugin-keys
New Plugins: Keys and Keys on map
This commit is contained in:
commit
e14baa9f3f
132
plugins/keys-on-map.user.js
Normal file
132
plugins/keys-on-map.user.js
Normal file
@ -0,0 +1,132 @@
|
||||
// ==UserScript==
|
||||
// @id iitc-plugin-keys-on-map@xelio
|
||||
// @name IITC plugin: Keys on map
|
||||
// @version 0.1.0.@@DATETIMEVERSION@@
|
||||
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
||||
// @updateURL @@UPDATEURL@@
|
||||
// @downloadURL @@DOWNLOADURL@@
|
||||
// @description [@@BUILDNAME@@-@@BUILDDATE@@] Show keys in keys plugin on map.
|
||||
// @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.keysOnMap = function() {};
|
||||
|
||||
window.plugin.keysOnMap.keyLayers = {};
|
||||
window.plugin.keysOnMap.keyLayerGroup = new L.LayerGroup();
|
||||
|
||||
// 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.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;
|
||||
}
|
||||
}
|
||||
|
||||
var setup = function() {
|
||||
$("<style>")
|
||||
.prop("type", "text/css")
|
||||
.html(".plugin-keys-on-map-key {\
|
||||
font-size: 10px;\
|
||||
color: #FFFFBB;\
|
||||
font-family: monospace;\
|
||||
text-align: center;\
|
||||
text-shadow: 0 0 0.5em black, 0 0 0.5em black, 0 0 0.5em black;\
|
||||
pointer-events: none;\
|
||||
-webkit-text-size-adjust:none;\
|
||||
}")
|
||||
.appendTo("head");
|
||||
|
||||
window.layerChooser.addOverlay(window.plugin.keysOnMap.keyLayerGroup, 'Keys');
|
||||
map.addLayer(window.plugin.keysOnMap.keyLayerGroup);
|
||||
|
||||
// Avoid error if this plugin load first
|
||||
if($.inArray('pluginKeysUpdateKey', window.VALID_HOOKS) < 0)
|
||||
window.VALID_HOOKS.push('pluginKeysUpdateKey');
|
||||
|
||||
window.addHook('portalAdded', window.plugin.keysOnMap.portalAdded);
|
||||
window.addHook('pluginKeysUpdateKey', window.plugin.keysOnMap.keyUpdate);
|
||||
}
|
||||
|
||||
// PLUGIN END //////////////////////////////////////////////////////////
|
||||
|
||||
if(window.iitcLoaded && typeof setup === 'function') {
|
||||
setup();
|
||||
} else {
|
||||
if(window.bootPlugins)
|
||||
window.bootPlugins.push(setup);
|
||||
else
|
||||
window.bootPlugins = [setup];
|
||||
}
|
||||
} // wrapper end
|
||||
// inject code into site context
|
||||
var script = document.createElement('script');
|
||||
script.appendChild(document.createTextNode('('+ wrapper +')();'));
|
||||
(document.body || document.head || document.documentElement).appendChild(script);
|
66
plugins/keys.css
Normal file
66
plugins/keys.css
Normal file
@ -0,0 +1,66 @@
|
||||
#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;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
#keys-add {
|
||||
}
|
||||
|
||||
#keys-count {
|
||||
width: 26px;
|
||||
height: 18px !important;
|
||||
border: 1px solid;
|
||||
text-align: center;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
#keys-help {
|
||||
font-weight: 900;
|
||||
margin: 6px 3px 1px 20px !important;
|
||||
cursor: help;
|
||||
}
|
125
plugins/keys.user.js
Normal file
125
plugins/keys.user.js
Normal file
@ -0,0 +1,125 @@
|
||||
// ==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.addToSidebar = function() {
|
||||
if(typeof(Storage) === "undefined") {
|
||||
$('#portaldetails > .imgpreview').after(plugin.keys.disabledMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
$('#portaldetails > .imgpreview').after(plugin.keys.contentHTML);
|
||||
plugin.keys.updateDisplayCount();
|
||||
}
|
||||
|
||||
window.plugin.keys.updateDisplayCount = 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.updateDisplayCount();
|
||||
window.runHooks('pluginKeysUpdateKey', {guid: guid, count: newCount});
|
||||
}
|
||||
}
|
||||
|
||||
window.plugin.keys.storeKeys = function() {
|
||||
var keysObject = {keys: plugin.keys.keys};
|
||||
var keysObjectJSON = JSON.stringify(keysObject);
|
||||
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() {
|
||||
$("<style>")
|
||||
.prop("type", "text/css")
|
||||
.html("@@INCLUDESTRING:plugins/keys.css@@")
|
||||
.appendTo("head");
|
||||
}
|
||||
|
||||
window.plugin.keys.setupContent = function() {
|
||||
plugin.keys.contentHTML = '<div id="keys-content-outer">'
|
||||
+ '<div id="keys-label" title="Problem? Point to the question mark!">Key(s):</div>'
|
||||
+ '<div id="keys-add" class="keys-button" '
|
||||
+ 'onclick="window.plugin.keys.addKey(-1);">'
|
||||
+ '<div class="keys-button-minus"></div>'
|
||||
+ '</div>'
|
||||
+ '<div id="keys-count" title="Problem? Point to the question mark!"></div>'
|
||||
+ '<div id="keys-subtract" class="keys-button" '
|
||||
+ 'onclick="window.plugin.keys.addKey(1);">'
|
||||
+ '<div class="keys-button-plus-v"></div>'
|
||||
+ '<div class="keys-button-plus-h"></div>'
|
||||
+ '</div>'
|
||||
+ '<div id="keys-help" title="You MUST manually input your count of keys!\n'
|
||||
+ 'This plugin CANNOT automatically get the keys from Ingress!">?</div>'
|
||||
+ '</div>';
|
||||
plugin.keys.disabledMessage = '<div id="keys-content-outer" title="Your browser do not support localStorage">Plugin Keys disabled</div>';
|
||||
}
|
||||
|
||||
var setup = function() {
|
||||
if($.inArray('pluginKeysUpdateKey', window.VALID_HOOKS) < 0)
|
||||
window.VALID_HOOKS.push('pluginKeysUpdateKey');
|
||||
|
||||
window.plugin.keys.setupCSS();
|
||||
window.plugin.keys.setupContent();
|
||||
window.plugin.keys.loadKeys();
|
||||
window.addHook('portalDetailsUpdated', window.plugin.keys.addToSidebar);
|
||||
}
|
||||
|
||||
// PLUGIN END //////////////////////////////////////////////////////////
|
||||
|
||||
if(window.iitcLoaded && typeof setup === 'function') {
|
||||
setup();
|
||||
} else {
|
||||
if(window.bootPlugins)
|
||||
window.bootPlugins.push(setup);
|
||||
else
|
||||
window.bootPlugins = [setup];
|
||||
}
|
||||
} // wrapper end
|
||||
// inject code into site context
|
||||
var script = document.createElement('script');
|
||||
script.appendChild(document.createTextNode('('+ wrapper +')();'));
|
||||
(document.body || document.head || document.documentElement).appendChild(script);
|
BIN
screenshots/plugin_keys.png
Normal file
BIN
screenshots/plugin_keys.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
BIN
screenshots/plugin_keys_on_map.png
Normal file
BIN
screenshots/plugin_keys_on_map.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
Loading…
x
Reference in New Issue
Block a user