Skip to content

Instantly share code, notes, and snippets.

@rddaz2013
Forked from yoshimov/ingress-comm.js
Created December 28, 2015 12:12
Show Gist options
  • Save rddaz2013/edf82872f67fd8164236 to your computer and use it in GitHub Desktop.
Save rddaz2013/edf82872f67fd8164236 to your computer and use it in GitHub Desktop.
Collect Ingress COMM log with PhantomJS
/* SETTINGS */
var l='';
var p='';
var area = 'https://www.ingress.com/intel?ll=35.5841133,139.4988137&z=14';
var v = 20000; //Delay between capturing screenshots, in milliseconds (1000 ms = 1 s)
var reloadtime = 60000 * 120;
var width = 900; //Picture width
var height = 500; //Picture height
var folder = './'; //Folder where to save screenshots, with / (or \) on the end. '.' means current folder.
phantom.injectJs('settings.js');
/* SGNITTES */
var page = require('webpage').create();
var system = require('system');
var twostep = 0;
var val, message, Le;
var Version = '1.3.1';
page.viewportSize = {
width: width + 42,
height: height + 167
};
function getDateTime() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth()+1;
var day = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
if(month.toString().length == 1) {
var month = '0'+month;
}
if(day.toString().length == 1) {
var day = '0'+day;
}
if(hour.toString().length == 1) {
var hour = '0'+hour;
}
if(minute.toString().length == 1) {
var minute = '0'+minute;
}
if(second.toString().length == 1) {
var second = '0'+second;
}
var dateTime = year+'-'+month+'-'+day+'--'+hour+'-'+minute+'-'+second;
return dateTime;
};
function s() {
console.log('Capturing screen from ' + getDateTime() + '...');
page.render(folder + 'Ice-' + getDateTime() + '.png');
};
function quit(err) {
if (err) {
console.log('\nICE crashed. Reason: ' + err + ' :('); //nice XD
} else {
console.log('Quit');
};
phantom.exit();
};
if (!l | !p) {
quit('you haven\'t entered your login and/or password');
};
function loadcomm() {
page.open(area, function () {
console.log('Authenticated successfully, starting gathering comm log every ' + v + 'ms...');
window.setTimeout(function() {
page.evaluate(function() {
var tab = document.querySelector('#pl_tab_all');
var e = document.createEvent('MouseEvent');
e.initEvent("click", true, false);
tab.dispatchEvent(e);
});
}, 5000);
var outputcomm = function() {
var exts = page.evaluate(function() {
var parent = document.querySelector('div#plexts');
var exts = parent.children;
var buf = "";
for (var i = 0; i < exts.length - 1; i ++) {
buf = buf + exts[i].outerHTML + "\n";
}
while (parent.firstChild && parent.firstChild != parent.lastChild) {
parent.removeChild(parent.firstChild);
}
var body = document.querySelector('body');
var e = document.createEvent('KeyboardEvent');
e.initKeyboardEvent("keypress",true,true,window,0,0,0,0,0,'a');
body.dispatchEvent(e);
return buf;
});
console.log(exts);
};
var intid = setInterval(outputcomm, v);
setTimeout(function() {
clearInterval(intid);
}, reloadtime - v);
});
};
window.setTimeout(function () {page.open('https://www.ingress.com/intel', function (status) {
if (status !== 'success') {quit('cannot connect to remote server')};
var inglink = page.evaluate(function () {
return document.getElementsByTagName('a')[0].href;
});
console.log('Logging in...');
page.open(inglink, function () {
page.evaluate(function (l) {
document.getElementById('Email').value = l;
}, l);
page.evaluate(function (p) {
document.getElementById('Passwd').value = p;
}, p);
page.evaluate(function () {
document.querySelector("input#signIn").click();
});
page.evaluate(function () {
document.getElementById('gaia_loginform').submit(); // Not using POST because the URI may change
});
window.setTimeout(function () {
console.log('URI is now ' + page.url.substring(0,40) + '... .\nVerifying login...');
if (page.url.substring(0,40) == 'https://accounts.google.com/ServiceLogin') {quit('login failed: wrong email and/or password')};
if (page.url.substring(0,40) == 'https://appengine.google.com/_ah/loginfo') {
console.log('Accepting appEngine request...');
page.evaluate(function () {
document.getElementById('persist_checkbox').checked = true;
document.getElementsByTagName('form').submit();
});
};
if (page.url.substring(0,40) == 'https://accounts.google.com/SecondFactor') {
console.log('Using two-step verification, please enter your code:');
twostep = system.stdin.readLine();
};
if (twostep) {
page.evaluate(function (code) {
document.getElementById('smsUserPin').value = code;
}, twostep);
page.evaluate(function () {
document.getElementById('gaia_secondfactorform').submit();
});
};
window.setTimeout(function() {
loadcomm();
setInterval(loadcomm, reloadtime);
}, 10000);
},5000);
});
});
}, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment