-
-
Save brainmachine/4509133 to your computer and use it in GitHub Desktop.
// ==UserScript== | |
// @name Ingress Player Locations | |
// @description Shows player locations on the Ingress Intel Map | |
// @version 1.2 | |
// @match http://www.ingress.com/intel | |
// @run-at document-start | |
// ==/UserScript== | |
function override() { | |
window.addEventListener('load', function() { | |
var df_orig = window.df; | |
window.df = function(a) { | |
df_orig(a); | |
window.map = a.h; | |
}; | |
window.players = {}; | |
var cd_orig = Lc.prototype.cd; | |
var blueIcon = 'https://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png'; | |
var greenIcon = 'https://maps.gstatic.com/mapfiles/ms2/micons/green-dot.png'; | |
function timeSince(date) { | |
var seconds = Math.floor((new Date() - date) / 1000); | |
var interval = Math.floor(seconds / 31536000); | |
if (interval > 1) { | |
return interval + " years ago"; | |
} | |
interval = Math.floor(seconds / 2592000); | |
if (interval > 1) { | |
return interval + " months ago"; | |
} | |
interval = Math.floor(seconds / 86400); | |
if (interval > 1) { | |
return interval + " days ago"; | |
} | |
interval = Math.floor(seconds / 3600); | |
if (interval > 1) { | |
return interval + " hours ago"; | |
} | |
interval = Math.floor(seconds / 60); | |
if (interval > 1) { | |
return interval + " minutes ago"; | |
} | |
return Math.floor(seconds) + " seconds ago"; | |
} | |
Lc.prototype.cd = function(a, b, c) { | |
if (a != 'dashboard.getPaginatedPlextsV2' || !c.hasOwnProperty('result')) { | |
return cd_orig.call(this, a, b, c); | |
} | |
var newPlayerData = {}; | |
for (var i = 0; i < c['result'].length; i++) { | |
var plext = c['result'][i][2]['plext']; | |
if (plext['plextType'] == 'SYSTEM_BROADCAST') { | |
var markup = plext['markup']; | |
var player; | |
var team; | |
var timestamp = c['result'][i][1]; | |
for (var j = 0; j < markup.length; j++) { | |
if (markup[j][0] == 'PLAYER') { | |
player = markup[j][1]['plain']; | |
team = markup[j][1]['team']; | |
} else if (markup[j][0] == 'PORTAL') { | |
var portal = markup[j][1]; | |
var latLng = new google.maps.LatLng( | |
portal['latE6'] / 1E6, | |
portal['lngE6'] / 1E6); | |
if (newPlayerData.hasOwnProperty(player) && | |
newPlayerData[player][0] > timestamp) { | |
continue; | |
} | |
newPlayerData[player] = [timestamp, team, latLng]; | |
} | |
} | |
} | |
} | |
for (var player in newPlayerData) { | |
var playerData = newPlayerData[player]; | |
var timestamp = playerData[0]; | |
var team = playerData[1]; | |
var latLng = playerData[2]; | |
if (players.hasOwnProperty(player)) { | |
var marker = players[player][1]; | |
marker.setTitle(player + ' (' + timeSince(new Date(timestamp)) + ')'); | |
if (players[player][0] < timestamp) { | |
players[player][0] = timestamp; | |
marker.setAnimation(null); | |
if (marker.getPosition().lat() == latLng.lat() && | |
marker.getPosition().lng() == latLng.lng()) { | |
marker.setAnimation(google.maps.Animation.BOUNCE); | |
window.setTimeout(function(marker) { marker.setAnimation(null); }, 5000, marker); | |
} else { | |
// Animate the marker movement to the new destination. | |
frames = []; | |
var oldLat = marker.getPosition().lat(); | |
var oldLng = marker.getPosition().lng(); | |
var newLat = latLng.lat(); | |
var newLng = latLng.lng(); | |
for (var percent = 0; percent < 1; percent += 0.01) { | |
var curLat = oldLat + percent * (newLat - oldLat); | |
var curLng = oldLng + percent * (newLng - oldLng); | |
frames.push(new google.maps.LatLng(curLat, curLng)); | |
} | |
var move = function(marker, latLngs, index, wait) { | |
marker.setPosition(latLngs[index]); | |
if (index != latLngs.length - 1) { | |
// call the next "frame" of the animation | |
setTimeout(function() { | |
move(marker, latLngs, index + 1, wait); | |
}, wait); | |
} | |
}; | |
move(marker, frames, 0, 20); | |
} | |
} | |
} else { | |
players[player] = [timestamp, new google.maps.Marker({ | |
map: window.map, | |
position: latLng, | |
animation: google.maps.Animation.DROP, | |
title: player + ' (' + timeSince(new Date(timestamp)) + ')', | |
icon: team == 'RESISTANCE' ? blueIcon : greenIcon | |
})]; | |
} | |
} | |
return cd_orig.call(this, a, b, c); | |
}; | |
}); | |
} | |
var script = document.createElement('script'); | |
script.appendChild(document.createTextNode('('+ override +')();')); | |
(document.body || document.head || document.documentElement).appendChild(script); |
Hi Brainmachine! Thank's for this tool. I want to write a script which will show all portals in my city and calculate distance between portals and required portal level to link them. I've already write code to show google map, show portals and calculate distance and level required. But all portals writen inside code. So it's usable only for my city now. And to add new portals it's required to modify script for each portal. I want to automatize procedure of getting portal coordinates but can't find how to get it from ingress/intel. I've seen in your code abowe object window. I've tried to find all it's method and properties but find only standard ones. Can you help to find description of where did you get position of players? Or how can i get coordinates of portals on map if i will click on it?
Was having problems getting this to work. Were there any plans to update this script and or include them in the https://github.com/breunigs/ingress-intel-total-conversion project?
bug: when user creates a link its new location becomes the link's target