Merge pull request #176 from Fragger/portals-list-nom-energy
Portals list nom energy, bugs, nits
This commit is contained in:
commit
e3d6b135ce
@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @id iitc-plugin-portals-list@teo96
|
// @id iitc-plugin-portals-list@teo96
|
||||||
// @name IITC plugin: show list of portals
|
// @name IITC plugin: show list of portals
|
||||||
// @version 0.0.10.@@DATETIMEVERSION@@
|
// @version 0.0.11.@@DATETIMEVERSION@@
|
||||||
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
||||||
// @updateURL @@UPDATEURL@@
|
// @updateURL @@UPDATEURL@@
|
||||||
// @downloadURL @@DOWNLOADURL@@
|
// @downloadURL @@DOWNLOADURL@@
|
||||||
@ -13,6 +13,8 @@
|
|||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
/* whatsnew
|
/* whatsnew
|
||||||
|
* 0.0.11: Add nominal energy column and # links, fix sort bug when opened even amounts of times, nits
|
||||||
|
* 0.0.10: Fixed persistent css problem with alert
|
||||||
* 0.0.9 : bugs hunt
|
* 0.0.9 : bugs hunt
|
||||||
* 0.0.8 : Aborted to avoid problems with Niantic (export portals informations as csv or kml file)
|
* 0.0.8 : Aborted to avoid problems with Niantic (export portals informations as csv or kml file)
|
||||||
* 0.0.7 : more informations avalaible via tooltips (who deployed, energy, ...), new E/AP column
|
* 0.0.7 : more informations avalaible via tooltips (who deployed, energy, ...), new E/AP column
|
||||||
@ -45,7 +47,7 @@ window.plugin.portalslist.resP = 0;
|
|||||||
window.plugin.portalslist.filter=0;
|
window.plugin.portalslist.filter=0;
|
||||||
|
|
||||||
//fill the listPortals array with portals avalaible on the map (level filtered portals will not appear in the table)
|
//fill the listPortals array with portals avalaible on the map (level filtered portals will not appear in the table)
|
||||||
window.plugin.portalslist.getPortals = function(){
|
window.plugin.portalslist.getPortals = function() {
|
||||||
//filter : 0 = All, 1 = Res, 2 = Enl
|
//filter : 0 = All, 1 = Res, 2 = Enl
|
||||||
//console.log('** getPortals');
|
//console.log('** getPortals');
|
||||||
var retval=false;
|
var retval=false;
|
||||||
@ -89,15 +91,16 @@ window.plugin.portalslist.getPortals = function(){
|
|||||||
//get shield informations
|
//get shield informations
|
||||||
var shields = [];
|
var shields = [];
|
||||||
$.each(d.portalV2.linkedModArray, function(ind, mod) {
|
$.each(d.portalV2.linkedModArray, function(ind, mod) {
|
||||||
if (mod)
|
if (mod) {
|
||||||
//shields[ind] = mod.rarity.capitalize().replace('_', ' ');
|
//shields[ind] = mod.rarity.capitalize().replace('_', ' ');
|
||||||
shields[ind] = [mod.rarity.substr(0,1).capitalize(), getPlayerName(mod.installingUser)] ;
|
shields[ind] = [mod.rarity.substr(0,1).capitalize(), getPlayerName(mod.installingUser)] ;
|
||||||
else
|
} else {
|
||||||
shields[ind] = ['', ''];
|
shields[ind] = ['', ''];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var APgain= getAttackApGain(d).enemyAp;
|
var APgain= getAttackApGain(d).enemyAp;
|
||||||
var thisPortal = {'portal':d,'name':name,'team':team,'level':level,'guid':guid, 'resonators':resonators,'energyratio' : Math.floor(energy/maxenergy*100), 'shields':shields, 'APgain':APgain, 'EAP' : (energy/APgain).toFixed(2), 'energy': energy, 'maxenergy':maxenergy, 'lat':portal._latlng.lat, 'lng':portal._latlng.lng, 'address': address, 'img' : img};
|
var thisPortal = {'portal': d, 'name': name, 'team': team, 'level': level, 'guid': guid, 'resonators': resonators, 'energyratio': maxenergy ? Math.floor(energy/maxenergy*100) : 0, 'shields': shields, 'APgain': APgain, 'EAP': (energy/APgain).toFixed(2), 'energy': energy, 'maxenergy': maxenergy, 'links': d.portalV2.linkedEdges.length, 'lat': portal._latlng.lat, 'lng': portal._latlng.lng, 'address': address, 'img': img};
|
||||||
window.plugin.portalslist.listPortals.push(thisPortal);
|
window.plugin.portalslist.listPortals.push(thisPortal);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -119,20 +122,23 @@ window.plugin.portalslist.displayPL = function() {
|
|||||||
} else {
|
} else {
|
||||||
html = '<table><tr><td>Nothing to Show !</td></tr></table>';
|
html = '<table><tr><td>Nothing to Show !</td></tr></table>';
|
||||||
};
|
};
|
||||||
alert('<div id="portalslist">' + html + '</div>', true, function() {$(".ui-dialog").removeClass('ui-dialog-portalslist');});
|
alert('<div id="portalslist">' + html + '</div>', true, function() {
|
||||||
|
$(".ui-dialog").removeClass('ui-dialog-portalslist');
|
||||||
|
$(document).off('.portalslist');
|
||||||
|
});
|
||||||
$(".ui-dialog").addClass('ui-dialog-portalslist');
|
$(".ui-dialog").addClass('ui-dialog-portalslist');
|
||||||
|
|
||||||
// Setup sorting
|
// Setup sorting
|
||||||
$(document).on('click', '#portalslist table th', function() {
|
$(document).on('click.portalslist', '#portalslist table th', function() {
|
||||||
$('#portalslist').html(window.plugin.portalslist.portalTable($(this).data('sort'),window.plugin.portalslist.sortOrder,window.plugin.portalslist.filter));
|
$('#portalslist').html(window.plugin.portalslist.portalTable($(this).data('sort'),window.plugin.portalslist.sortOrder,window.plugin.portalslist.filter));
|
||||||
});
|
});
|
||||||
$(document).on('click', '#portalslist .filterAll', function() {
|
$(document).on('click.portalslist', '#portalslist .filterAll', function() {
|
||||||
$('#portalslist').html(window.plugin.portalslist.portalTable($(this).data('sort'),window.plugin.portalslist.sortOrder,0));
|
$('#portalslist').html(window.plugin.portalslist.portalTable($(this).data('sort'),window.plugin.portalslist.sortOrder,0));
|
||||||
});
|
});
|
||||||
$(document).on('click', '#portalslist .filterRes', function() {
|
$(document).on('click.portalslist', '#portalslist .filterRes', function() {
|
||||||
$('#portalslist').html(window.plugin.portalslist.portalTable($(this).data('sort'),window.plugin.portalslist.sortOrder,1));
|
$('#portalslist').html(window.plugin.portalslist.portalTable($(this).data('sort'),window.plugin.portalslist.sortOrder,1));
|
||||||
});
|
});
|
||||||
$(document).on('click', '#portalslist .filterEnl', function() {
|
$(document).on('click.portalslist', '#portalslist .filterEnl', function() {
|
||||||
$('#portalslist').html(window.plugin.portalslist.portalTable($(this).data('sort'),window.plugin.portalslist.sortOrder,2));
|
$('#portalslist').html(window.plugin.portalslist.portalTable($(this).data('sort'),window.plugin.portalslist.sortOrder,2));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -193,7 +199,7 @@ window.plugin.portalslist.portalTable = function(sortBy, sortOrder, filter) {
|
|||||||
retVal = b[sortBy] - a[sortBy];
|
retVal = b[sortBy] - a[sortBy];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (sortOrder > 0) { retVal = -retVal} //thx @jonatkins
|
if (sortOrder > 0) retVal = -retVal; //thx @jonatkins
|
||||||
return retVal;
|
return retVal;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -211,7 +217,9 @@ window.plugin.portalslist.portalTable = function(sortBy, sortOrder, filter) {
|
|||||||
+ '<th ' + sort('r6', sortBy, -1) + '>R6</th>'
|
+ '<th ' + sort('r6', sortBy, -1) + '>R6</th>'
|
||||||
+ '<th ' + sort('r7', sortBy, -1) + '>R7</th>'
|
+ '<th ' + sort('r7', sortBy, -1) + '>R7</th>'
|
||||||
+ '<th ' + sort('r8', sortBy, -1) + '>R8</th>'
|
+ '<th ' + sort('r8', sortBy, -1) + '>R8</th>'
|
||||||
+ '<th ' + sort('energyratio', sortBy, -1) + '>Energy</th>'
|
+ '<th ' + sort('energy', sortBy, -1) + '>Energy</th>'
|
||||||
|
+ '<th ' + sort('energyratio', sortBy, -1) + '>%</th>'
|
||||||
|
+ '<th ' + sort('links', sortBy, -1) + '>Links</th>'
|
||||||
+ '<th ' + sort('s1', sortBy, -1) + '>S1</th>'
|
+ '<th ' + sort('s1', sortBy, -1) + '>S1</th>'
|
||||||
+ '<th ' + sort('s2', sortBy, -1) + '>S2</th>'
|
+ '<th ' + sort('s2', sortBy, -1) + '>S2</th>'
|
||||||
+ '<th ' + sort('s3', sortBy, -1) + '>S3</th>'
|
+ '<th ' + sort('s3', sortBy, -1) + '>S3</th>'
|
||||||
@ -222,23 +230,27 @@ window.plugin.portalslist.portalTable = function(sortBy, sortOrder, filter) {
|
|||||||
|
|
||||||
$.each(portals, function(ind, portal) {
|
$.each(portals, function(ind, portal) {
|
||||||
|
|
||||||
if (filter === 0 || filter === portal.team){
|
if (filter === 0 || filter === portal.team) {
|
||||||
html += '<tr class="' + (portal.team === 1 ? 'res' : (portal.team === 2 ? 'enl' : 'neutral')) + '">'
|
html += '<tr class="' + (portal.team === 1 ? 'res' : (portal.team === 2 ? 'enl' : 'neutral')) + '">'
|
||||||
+ '<td style="">' + window.plugin.portalslist.getPortalLink(portal.portal, portal.guid) + '</td>'
|
+ '<td style="">' + window.plugin.portalslist.getPortalLink(portal.portal, portal.guid) + '</td>'
|
||||||
+ '<td class="L' + Math.floor(portal.level) +'">' + portal.level + '</td>'
|
+ '<td class="L' + Math.floor(portal.level) +'">' + portal.level + '</td>'
|
||||||
+ '<td style="text-align:center;">' + portal.team + '</td>';
|
+ '<td style="text-align:center;">' + portal.team + '</td>';
|
||||||
|
|
||||||
|
var title;
|
||||||
|
var percent;
|
||||||
$.each([0, 1, 2, 3 ,4 ,5 ,6 ,7], function(ind, slot) {
|
$.each([0, 1, 2, 3 ,4 ,5 ,6 ,7], function(ind, slot) {
|
||||||
|
percent = portal.resonators[slot][4] ? Math.floor(portal.resonators[slot][3]/portal.resonators[slot][4]*100) : 0;
|
||||||
var title = 'title="owner: <b>' + portal.resonators[slot][1] + '</b><br>'
|
title = 'title="owner: <b>' + portal.resonators[slot][1] + '</b><br>'
|
||||||
+ 'energy: ' + portal.resonators[slot][3] + ' / ' + portal.resonators[slot][4] + ' (' + Math.floor(portal.resonators[slot][3]/portal.resonators[slot][4]*100) + '%)<br>'
|
+ 'energy: ' + portal.resonators[slot][3] + ' / ' + portal.resonators[slot][4] + ' (' + percent + '%)<br>'
|
||||||
+ 'distance: ' + portal.resonators[slot][2] + 'm';
|
+ 'distance: ' + portal.resonators[slot][2] + 'm';
|
||||||
|
|
||||||
html += '<td class="L' + portal.resonators[slot][0] +'" ' + title + '">' + portal.resonators[slot][0] + '</td>';
|
html += '<td class="L' + portal.resonators[slot][0] +'" ' + title + '">' + portal.resonators[slot][0] + '</td>';
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
html += '<td style="cursor:help" title="' + portal.energy + ' / ' + portal.maxenergy +'">' + portal.energyratio + '%</td>'
|
html += '<td style="cursor:help" title="'+ portal.energy +'">' + prettyEnergy(portal.energy) + '</td>'
|
||||||
|
+ '<td style="cursor:help" title="' + portal.energy + ' / ' + portal.maxenergy +'">' + portal.energyratio + '%</td>'
|
||||||
|
+ '<td style="cursor:help" title="' + portal.links + '">' + portal.links + '</td>'
|
||||||
+ '<td style="cursor:help" title="'+ portal.shields[0][1] +'">' + portal.shields[0][0] + '</td>'
|
+ '<td style="cursor:help" title="'+ portal.shields[0][1] +'">' + portal.shields[0][0] + '</td>'
|
||||||
+ '<td style="cursor:help" title="'+ portal.shields[1][1] +'">' + portal.shields[1][0] + '</td>'
|
+ '<td style="cursor:help" title="'+ portal.shields[1][1] +'">' + portal.shields[1][0] + '</td>'
|
||||||
+ '<td style="cursor:help" title="'+ portal.shields[2][1] +'">' + portal.shields[2][0] + '</td>'
|
+ '<td style="cursor:help" title="'+ portal.shields[2][1] +'">' + portal.shields[2][0] + '</td>'
|
||||||
@ -251,8 +263,6 @@ window.plugin.portalslist.portalTable = function(sortBy, sortOrder, filter) {
|
|||||||
});
|
});
|
||||||
html += '</table>';
|
html += '</table>';
|
||||||
|
|
||||||
//html += window.plugin.portalslist.exportLinks();
|
|
||||||
|
|
||||||
html += '<div class="disclaimer">Click on portals table headers to sort by that column. '
|
html += '<div class="disclaimer">Click on portals table headers to sort by that column. '
|
||||||
+ 'Click on <b>All Portals, Resistant Portals, Enlightened Portals</b> to filter<br>'
|
+ 'Click on <b>All Portals, Resistant Portals, Enlightened Portals</b> to filter<br>'
|
||||||
+ 'Thanks to @vita10gy & @xelio for their IITC plugins who inspired me. A <a href="https://plus.google.com/113965246471577467739">@teo96</a> production. Vive la Résistance !</div>';
|
+ 'Thanks to @vita10gy & @xelio for their IITC plugins who inspired me. A <a href="https://plus.google.com/113965246471577467739">@teo96</a> production. Vive la Résistance !</div>';
|
||||||
@ -272,103 +282,6 @@ window.plugin.portalslist.stats = function(sortBy) {
|
|||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
//return Html generated to export links
|
|
||||||
window.plugin.portalslist.exportLinks = function(){
|
|
||||||
var html='';
|
|
||||||
var stamp = new Date().getTime();
|
|
||||||
|
|
||||||
html+='<div><aside><a download="Ingress Export.csv" href="' + window.plugin.portalslist.export('csv') + '">Export as .csv</a></aside>'
|
|
||||||
+ '<aside><a download="Ingress Export.kml" href="' + window.plugin.portalslist.export('kml') + '">Export as .kml</a></aside>'
|
|
||||||
+ '</div>';
|
|
||||||
return html;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.plugin.portalslist.export = function(fileformat){
|
|
||||||
//alert('format :' + fileformat);
|
|
||||||
var file = '';
|
|
||||||
var uri = '';
|
|
||||||
|
|
||||||
switch (fileformat) {
|
|
||||||
case 'csv':
|
|
||||||
file = window.plugin.portalslist.exportCSV();
|
|
||||||
break;
|
|
||||||
case 'kml':
|
|
||||||
file = window.plugin.portalslist.exportKML();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file !== '') {
|
|
||||||
//http://stackoverflow.com/questions/4639372/export-to-csv-in-jquery
|
|
||||||
var uri = 'data:application/' + fileformat + 'csv;charset=UTF-8,' + encodeURIComponent(file);
|
|
||||||
//window.open(uri);
|
|
||||||
}
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
window.plugin.portalslist.exportCSV = function(){
|
|
||||||
var csv = '';
|
|
||||||
var filter = window.plugin.portalslist.filter;
|
|
||||||
var portals = window.plugin.portalslist.listPortals;
|
|
||||||
|
|
||||||
//headers
|
|
||||||
csv += 'Portal\tLevel\tTeam\tR1\tR2\tR3\tR4\tR5\tR6\tR7\tR8\tEnergy\tS1\tS2\tS3\tS4\tAP Gain\tE/AP\tlat\tlong\n';
|
|
||||||
|
|
||||||
$.each(portals, function(ind, portal) {
|
|
||||||
|
|
||||||
if (filter === 0 || filter === portal.team){
|
|
||||||
csv += portal.name + '\t'
|
|
||||||
+ portal.level + '\t'
|
|
||||||
+ portal.team + '\t';
|
|
||||||
|
|
||||||
$.each([0, 1, 2, 3 ,4 ,5 ,6 ,7], function(ind, slot) {
|
|
||||||
csv += portal.resonators[slot][0] + '\t';
|
|
||||||
});
|
|
||||||
|
|
||||||
csv += portal.energyratio + '\t' + portal.shields[0][0] + '\t' + portal.shields[1][0] + '\t' + portal.shields[2][0] + '\t' + portal.shields[3][0] + '\t' + portal.APgain + '\t' + portal.EAP + '\t';
|
|
||||||
csv += portal.lat + '\t' + portal.lng;
|
|
||||||
csv += '\n';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return csv;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.plugin.portalslist.exportKML = function(){
|
|
||||||
var kml = '';
|
|
||||||
var filter = window.plugin.portalslist.filter;
|
|
||||||
// all portals informations are avalaible in the listPortals array
|
|
||||||
var portals = window.plugin.portalslist.listPortals;
|
|
||||||
|
|
||||||
//headers
|
|
||||||
kml = '<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2"><Document>\n'
|
|
||||||
+ '<name>Ingress Export</name><description><![CDATA[Ingress Portals\nExported from IITC using the Portals-list plugin\n' + new Date().toLocaleString() + ']]></description>';
|
|
||||||
|
|
||||||
// define colored markers as style0 (neutral), style1 (Resistance), style2 (Enlight)
|
|
||||||
kml += '<Style id="style1"><IconStyle><Icon><href>http://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png</href></Icon></IconStyle></Style>'
|
|
||||||
+ '<Style id="style2"><IconStyle><Icon><href>http://maps.gstatic.com/mapfiles/ms2/micons/green-dot.png</href></Icon></IconStyle></Style>'
|
|
||||||
+ '<Style id="style0"><IconStyle><Icon><href>http://maps.gstatic.com/mapfiles/ms2/micons/pink-dot.png</href></Icon></IconStyle></Style>\n';
|
|
||||||
|
|
||||||
$.each(portals, function(ind, portal) {
|
|
||||||
// add the portal in the kml file only if part of the filter choice
|
|
||||||
if (filter === 0 || filter === portal.team){
|
|
||||||
// description contain picture of the portal, address and link to the Intel map
|
|
||||||
var description = '<![CDATA['
|
|
||||||
+ '<div><table><tr><td><img style="width:100px" src="' + portal.img + '"></td><td>' + portal.address
|
|
||||||
+ '<br><a href="https://www.ingress.com/intel?latE6=' + portal.lat*1E6 + '&lngE6=' + portal.lng*1E6 + '&z=17">Link to Intel Map</a></td></tr></table>'
|
|
||||||
+ ']]>';
|
|
||||||
|
|
||||||
kml += '<Placemark><name>L' + Math.floor(portal.level) + ' - ' + portal.name + '</name>'
|
|
||||||
+ '<description>' + description + '</description>'
|
|
||||||
+ '<styleUrl>#style' + portal.team + '</styleUrl>';
|
|
||||||
|
|
||||||
//coordinates
|
|
||||||
kml += '<Point><coordinates>' + portal.lng + ',' + portal.lat + ',0</coordinates></Point>';
|
|
||||||
kml += '</Placemark>\n';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
kml += '</Document></kml>';
|
|
||||||
return kml;
|
|
||||||
}
|
|
||||||
|
|
||||||
// A little helper functon so the above isn't so messy
|
// A little helper functon so the above isn't so messy
|
||||||
window.plugin.portalslist.portalTableSort = function(name, by) {
|
window.plugin.portalslist.portalTableSort = function(name, by) {
|
||||||
var retVal = 'data-sort="' + name + '"';
|
var retVal = 'data-sort="' + name + '"';
|
||||||
@ -403,9 +316,9 @@ window.plugin.portalslist.getPortalLink = function(portal,guid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var setup = function() {
|
var setup = function() {
|
||||||
$('#toolbox').append(' <a onclick="window.plugin.portalslist.displayPL(0)" title="Display a list of portals in the current view">Portals list</a>');
|
$('#toolbox').append(' <a onclick="window.plugin.portalslist.displayPL()" title="Display a list of portals in the current view">Portals list</a>');
|
||||||
$('head').append('<style>' +
|
$('head').append('<style>' +
|
||||||
'.ui-dialog-portalslist {position: absolute !important; top: 10px !important; left: 30px !important;max-width:800px !important; width:733px !important;}' +
|
'.ui-dialog-portalslist {position: absolute !important; top: 10px !important; left: 30px !important;max-width:800px !important; width:auto !important;}' +
|
||||||
'#portalslist table {margin-top:5px; border-collapse: collapse; empty-cells: show; width:100%; clear: both;}' +
|
'#portalslist table {margin-top:5px; border-collapse: collapse; empty-cells: show; width:100%; clear: both;}' +
|
||||||
'#portalslist table td, #portalslist table th {border-bottom: 1px solid #0b314e; padding:3px; color:white; background-color:#1b415e}' +
|
'#portalslist table td, #portalslist table th {border-bottom: 1px solid #0b314e; padding:3px; color:white; background-color:#1b415e}' +
|
||||||
'#portalslist table tr.res td { background-color: #005684; }' +
|
'#portalslist table tr.res td { background-color: #005684; }' +
|
||||||
|
Loading…
x
Reference in New Issue
Block a user