NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

// vim:ts=2:sw=2:expandtab
// ==UserScript==
// @id iitc-list-active-players-pseud0
// @name IITC plugin: list active players
// @category Info
// @version 0.1
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @description Lists all active players and their active time.
// @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel*
// @match https://www.ingress.com/intel*
// @match http://www.ingress.com/intel*
// @include https://www.ingress.com/mission/*
// @include http://www.ingress.com/mission/*
// @match https://www.ingress.com/mission/*
// @match http://www.ingress.com/mission/*
// @grant none
// ==/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 AUTHORS: writing a plugin outside of the IITC build environment? if so, delete these lines!!
//(leaving them in place might break the 'About IITC' page or break update checks)
plugin_info.buildName = 'mobile';
plugin_info.dateTimeVersion = '20150907.121027';
plugin_info.pluginId = 'active-players';
//END PLUGIN AUTHORS NOTE



// max time: 24 hours
window.LIST_ACTIVE_PLAYERS_MAX_TIME = 24*60*60*1000;
window.LIST_ACTIVE_PLAYERS_MIN_ZOOM = 10;

window.plugin.listActivePlayers = function () {};

window.plugin.listActivePlayers.setup = function () {
if(window.useAndroidPanes()) {
android.addPane("plugin-listActivePlayers", "Active Players", "ic_action_paste");
addHook("paneChanged", window.plugin.listActivePlayers.onPaneChanged);
} else {
$('#toolbox').append(' <a onclick="window.plugin.listActivePlayers.displayList()" title="Display a list of active players in the current view">Active Players</a>');
}

$('head').append('<style>' +
'#listActivePlayers.mobile {background: transparent; border: 0 none !important; height: 100% !important; width: 100% !important; left: 0 !important; top: 0 !important; position: absolute; overflow: auto; }' +
'#listActivePlayers table { margin-top:5px; border-collapse: collapse; empty-cells: show; width: 100%; clear: both; }' +
'#listActivePlayers table td, #listActivePlayers table th {border-bottom: 1px solid #0b314e; padding:3px; color:white; background-color:#1b415e; }' +
'</style>');


addHook('publicChatDataAvailable', window.plugin.listActivePlayers.handleData);

}

window.plugin.listActivePlayers.humanReadableTime = function (time) {
var s = time / 1000;
var h = Math.floor(s / 3600);
var m = Math.floor((s % 3600) / 60);
var returnVal = m + 'm';
if (h > 0) {
returnVal = h + 'h' + returnVal;
}
return returnVal;
}

window.plugin.listActivePlayers.getTotalActive = function (first, last) {
var totalTime = last - first;
return window.plugin.listActivePlayers.humanReadableTime(totalTime);
}

window.plugin.listActivePlayers.getResHtml = function() {
var cnt = 0;
$.each(plugin.listActivePlayers.stored, function(pguid, player) {
if (player.team == TEAM_RES) cnt += 1;
});
var html = '<tr align="left"><td><b><font color=' + COLORS[TEAM_RES] + '>RESISTANCE</font></b></td>' +
'<td><b>Active Players:</b></td> <td><b>' + cnt + '</b></td><td></td></tr>';
html += window.plugin.listActivePlayers.getHtml(TEAM_RES);
return html;
}

window.plugin.listActivePlayers.getEnlHtml = function() {
var cnt = 0;
$.each(plugin.listActivePlayers.stored, function(pguid, player) {
if (player.team == TEAM_ENL) cnt += 1;
});
var html = '<tr align="left"><td><b><font color=' + COLORS[TEAM_ENL] + '>ENLIGHTENED</font></b></td>' +
'<td><b>Active Players:</b></td> <td><b>' + cnt + '</b></td><td></td></tr>';
html += window.plugin.listActivePlayers.getHtml(TEAM_ENL);
return html;
}

window.plugin.listActivePlayers.getHtml = function(displayTeam) {
var html = '<tr align="left"><td><b>Name</b></td> <td><b>Total Time</b></td> <td><b>First Event</b></td> <td><b>Last Event</b></td></tr>';
$.each(plugin.listActivePlayers.stored, function(pguid, player) {
if (player.team != displayTeam) return true;
var ev = player.events;
var color = COLORS[player.team];
if (ev.length < 2) return true;
var firstTime = ev[0].time;
var firstDate = new Date(firstTime);
var lastTime = ev[ev.length - 1].time;
var lastDate = new Date(lastTime);
var totalTime = window.plugin.listActivePlayers.getTotalActive(firstTime, lastTime);
html += '<tr align="left"><td><font color=' + color + '>' + pguid + '</font></td>'
+ '<td>' + totalTime + '</td>'
+ '<td>' + firstDate.toLocaleTimeString() + '</td>'
+ '<td>' + lastDate.toLocaleTimeString() + '</td></tr>';
});
return html;
}

window.plugin.listActivePlayers.displayList = function() {
var html = '<table>';
if (PLAYER.team === 'RESISTANCE') {
html += window.plugin.listActivePlayers.getResHtml();
html += window.plugin.listActivePlayers.getEnlHtml();
} else {
html += window.plugin.listActivePlayers.getEnlHtml();
html += window.plugin.listActivePlayers.getResHtml();
}
html += '</table>';
if(window.useAndroidPanes()) {
$('<div id="listActivePlayers" class="mobile">' + html + '</div>').appendTo(document.body);
} else {
dialog({
html: '<div id="listActivePlayers">' + html + '</div>',
dialogClass: 'ui-dialog-listActivePlayers',
title: 'Active Players',
id: 'list-active-players',
width: 500
});
}
}

window.plugin.listActivePlayers.onPaneChanged = function(pane) {
if(pane == "plugin-listActivePlayers")
window.plugin.listActivePlayers.displayList();
else
$("#listActivePlayers").remove()
};

window.plugin.listActivePlayers.getLimit = function() {
return new Date().getTime() - window.LIST_ACTIVE_PLAYERS_MAX_TIME;
}

window.plugin.listActivePlayers.stored = {};

window.plugin.listActivePlayers.discardOldData = function() {
var limit = plugin.listActivePlayers.getLimit();
$.each(plugin.listActivePlayers.stored, function(pguid, player) {
var i;
var ev = player.events;
for(i = 0; i < ev.length; i++) {
if(ev[i].time >= limit) break;
}
if(i === 0) return true;
if(i === ev.length) return delete plugin.listActivePlayers.stored[pguid];
plugin.listActivePlayers.stored[pguid].events.splice(0, i);
});
}

window.plugin.listActivePlayers.processNewData = function(data) {
var limit = plugin.listActivePlayers.getLimit();
$.each(data.result, function(ind, json) {

// skip old data
if(json[1] < limit) return true;

// find player and portal information
var pguid, guid;
var skipThisMessage = false;
$.each(json[2].plext.markup, function(ind, markup) {
switch(markup[0]) {
case 'PLAYER':
pguid = markup[1].plain;
break;
case 'PORTAL':
guid = guid ? guid : markup[1].guid;
break;
}
});

// skip unusable events
if(!pguid) return true;

var newEvent = {
guids: [guid],
time: json[1]
};

var playerData = window.plugin.listActivePlayers.stored[pguid];
var team = json[2].plext.team === 'RESISTANCE' ? TEAM_RES : TEAM_ENL;

// short-path if this is a new player
if(!playerData || playerData.events.length === 0) {
plugin.listActivePlayers.stored[pguid] = {
// this always resolves, as the chat delivers this data
nick: pguid,
team: team,
events: [newEvent]
};
return true;
}

var evts = playerData.events;
// there’s some data already. Need to find correct place to insert.
var i;
for(i = 0; i < evts.length; i++) {
if(evts[i].time > json[1]) break;
}

var cmp = Math.max(i-1, 0);

// so we have an event that happened at the same time. Most likely
// this is multiple resos destroyed at the same time.
if(evts[cmp].time === json[1]) {
evts[cmp].guids.push(guid);
plugin.listActivePlayers.stored[pguid].events = evts;
return true;
}

evts.splice(i, 0, newEvent);

// update player data
plugin.listActivePlayers.stored[pguid].events = evts;
});
}

window.plugin.listActivePlayers.handleData = function(data) {
if(window.map.getZoom() < window.LIST_ACTIVE_PLAYERS_MIN_ZOOM) return;

plugin.listActivePlayers.discardOldData();
plugin.listActivePlayers.processNewData(data);
}

var setup = plugin.listActivePlayers.setup;



setup.info = plugin_info; //add the script info data to the function as a property
if(!window.bootPlugins) window.bootPlugins = [];
window.bootPlugins.push(setup);
// if IITC has already booted, immediately run the 'setup' function
if(window.iitcLoaded && typeof setup === 'function') setup();
} // wrapper end
// inject code into site context
var script = document.createElement('script');
var info = {};
if (typeof GM_info !== 'undefined' && GM_info && GM_info.script) info.script = { version: GM_info.script.version, name: GM_info.script.name, description: GM_info.script.description };
script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));
(document.body || document.head || document.documentElement).appendChild(script);

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.