- 1 :
/* global log -- eslint */
- 2 :
- 3 :
/**
- 4 :
* Extract essential parameters and functions from the Ingress Intel site's minified JavaScript.
- 5 :
* Necessary due to Niantic's minification and obfuscation of their Intel Map code.
- 6 :
*
- 7 :
* @module extract_niantic_parameters
- 8 :
*/
- 9 :
- 10 :
/**
- 11 :
* Main function to extract required parameters from the Ingress Intel site's JavaScript.
- 12 :
* Throws an error and shows a dialog if it fails to find the necessary parameters.
- 13 :
*
- 14 :
* @function extractFromStock
- 15 :
*/
- 16 :
- 17 :
window.extractFromStock = function () {
- 18 :
window.niantic_params = {};
- 19 :
- 20 :
// extract the former nemesis.dashboard.config.CURRENT_VERSION from the code
- 21 :
var reVersion = new RegExp('"X-CSRFToken".*[a-z].v="([a-f0-9]{40})";');
- 22 :
- 23 :
var minified = new RegExp('^[a-zA-Z$][a-zA-Z$0-9]?$');
- 24 :
- 25 :
for (var topLevel in window) {
- 26 :
if (minified.test(topLevel)) {
- 27 :
// a minified object - check for minified prototype entries
- 28 :
- 29 :
var topObject = window[topLevel];
- 30 :
if (topObject && topObject.prototype) {
- 31 :
// the object has a prototype - iterate through the properties of that
- 32 :
for (var secLevel in topObject.prototype) {
- 33 :
if (minified.test(secLevel)) {
- 34 :
// looks like we've found an object of the format "XX.prototype.YY"...
- 35 :
var item = topObject.prototype[secLevel];
- 36 :
- 37 :
if (item && typeof item === 'function') {
- 38 :
// a function - test it against the relevant regular expressions
- 39 :
var funcStr = item.toString();
- 40 :
- 41 :
var match = reVersion.exec(funcStr);
- 42 :
if (match) {
- 43 :
log.log('Found former CURRENT_VERSION in ' + topLevel + '.prototype.' + secLevel);
- 44 :
window.niantic_params.CURRENT_VERSION = match[1];
- 45 :
}
- 46 :
}
- 47 :
}
- 48 :
}
- 49 :
} // end 'if .prototype'
- 50 :
- 51 :
if (topObject && Array.isArray && Array.isArray(topObject)) {
- 52 :
// find all non-zero length arrays containing just numbers
- 53 :
if (topObject.length > 0) {
- 54 :
var justInts = true;
- 55 :
for (var i = 0; i < topObject.length; i++) {
- 56 :
if (typeof topObject[i] !== 'number' || topObject[i] !== parseInt(topObject[i])) {
- 57 :
justInts = false;
- 58 :
break;
- 59 :
}
- 60 :
}
- 61 :
if (justInts) {
- 62 :
// current lengths are: 17: ZOOM_TO_LEVEL, 14: TILES_PER_EDGE
- 63 :
// however, slightly longer or shorter are a possibility in the future
- 64 :
- 65 :
if (topObject.length >= 12 && topObject.length <= 18) {
- 66 :
// a reasonable array length for tile parameters
- 67 :
// need to find two types:
- 68 :
// a. portal level limits. decreasing numbers, starting at 8
- 69 :
// b. tiles per edge. increasing numbers. current max is 36000, 9000 was the previous value - 18000 is a likely possibility too
- 70 :
- 71 :
if (topObject[0] === 8) {
- 72 :
// check for tile levels
- 73 :
var decreasing = true;
- 74 :
for (let i = 1; i < topObject.length; i++) {
- 75 :
if (topObject[i - 1] < topObject[i]) {
- 76 :
decreasing = false;
- 77 :
break;
- 78 :
}
- 79 :
}
- 80 :
if (decreasing) {
- 81 :
window.niantic_params.ZOOM_TO_LEVEL = topObject;
- 82 :
}
- 83 :
} // end if (topObject[0] == 8)
- 84 :
- 85 :
// 2015-06-25 - changed to top value of 64000, then to 32000 - allow for them to restore it just in case
- 86 :
if (topObject[topObject.length - 1] >= 9000 && topObject[topObject.length - 1] <= 64000) {
- 87 :
var increasing = true;
- 88 :
for (let i = 1; i < topObject.length; i++) {
- 89 :
if (topObject[i - 1] > topObject[i]) {
- 90 :
increasing = false;
- 91 :
break;
- 92 :
}
- 93 :
}
- 94 :
if (increasing) {
- 95 :
window.niantic_params.TILES_PER_EDGE = topObject;
- 96 :
}
- 97 :
} // end if (topObject[topObject.length-1] == 9000) {
- 98 :
}
- 99 :
}
- 100 :
}
- 101 :
}
- 102 :
}
- 103 :
}
- 104 :
- 105 :
if (window.niantic_params.CURRENT_VERSION === undefined) {
- 106 :
window.dialog({
- 107 :
title: 'IITC Broken',
- 108 :
html:
- 109 :
'<p>IITC failed to extract the required parameters from the intel site</p>' +
- 110 :
'<p>This can happen after Niantic update the standard intel site. A fix will be needed from the IITC developers.</p>',
- 111 :
});
- 112 :
- 113 :
log.log('Discovered parameters');
- 114 :
log.log(JSON.stringify(window.niantic_params, null, 2));
- 115 :
- 116 :
throw new Error('Error: IITC failed to extract CURRENT_VERSION string - cannot continue');
- 117 :
}
- 118 :
};