Skip to content

Instantly share code, notes, and snippets.

@dpogue
Created May 30, 2013 03:26
Show Gist options
  • Save dpogue/5675554 to your computer and use it in GitHub Desktop.
Save dpogue/5675554 to your computer and use it in GitHub Desktop.
PhantomJS script for capturing screenshots of the Ingress Intel map.
var page= require('webpage').create(),
system = require('system');
var url = 'http://www.ingress.com/intel';
var date = (new Date()).toISOString();
var output = '{{PATH}}' + date + '.png';
phantom.addCookie({
name: 'ACSID',
value: '{{ACSID}}',
domain: 'www.ingress.com',
path: '/',
httponly: true,
expires: 'Tue, 19 Feb 2013 05:30:24 GMT'
});
phantom.addCookie({
name: 'csrftoken',
value: '{{TOKEN}}',
domain: 'www.ingress.com',
path: '/',
expires: 'Tue, 04 Feb 2014 05:30:42 GMT'
});
phantom.addCookie({
name: 'ingress.intelmap.lat',
value: '{{LATITUDE}}',
domain: 'www.ingress.com',
path: '/'
});
phantom.addCookie({
name: 'ingress.intelmap.lng',
value: '{{LONGITUDE}}',
domain: 'www.ingress.com',
path: '/'
});
phantom.addCookie({
name: 'ingress.intelmap.zoom',
value: '11',
domain: 'www.ingress.com',
path: '/'
});
page.viewportSize = { width: 1600, height: 1024 };
function takeMapshot(i) {
if (i >= 5) {
console.error('Failing after 5 tries');
phantom.exit();
return;
}
page.open(url, function(st) {
if (st !== 'success') {
console.log('Failed to open page');
phantom.exit();
} else {
var hasMap = page.evaluate(function() {
return document.querySelector('#map_canvas');
});
if (hasMap) {
window.setTimeout(function() {
page.evaluate(function() {
var comm, pstats, geosearch, redeem, header;
if (comm = document.querySelector('#comm')) {
comm.style.display = 'none';
}
if (pstats = document.querySelector('#player_stats')) {
pstats.style.display = 'none';
}
if (geosearch = document.querySelector('#geocode_search')) {
geosearch.style.display = 'none';
}
if (redeem = document.querySelector('#redeem_reward')) {
redeem.style.display = 'none';
}
if (header = document.querySelector('#header')) {
header.style.display = 'none';
}
var nl = document.querySelectorAll('.gmnoprint');
for (var i = 0, ii = nl.length; i < ii; ++i) {
nl.item(i).style.display = 'none';
}
});
window.setTimeout(function() {
page.render(output);
phantom.exit();
}, 60000);
}, 60000);
} else {
/* recurse */
console.log('Attempt ' + i);
takeMapshot(i + 1);
}
}
});
}
takeMapshot(0);
Copy link

ghost commented Jul 11, 2014

Oh... I didn't see this and made a tool like this ๐Ÿ˜Š. It's here. My way was harder ๐Ÿ˜„, I authenticate user and then capture screenshots, without using cookies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment