Skip to content

Instantly share code, notes, and snippets.

@wfjsw
Last active February 25, 2017 07:25
Show Gist options
  • Save wfjsw/058602d9a4653a9a05d7bd873217936a to your computer and use it in GitHub Desktop.
Save wfjsw/058602d9a4653a9a05d7bd873217936a to your computer and use it in GitHub Desktop.
// ==UserScript==
// @id iitc_patch_artifact01
// @name WFENL-Toolkit IITC plugin: Fix Artifact Target Team Recognize
// @category Hack
// @version 0.0.1.20170130.000005
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL https://gist.github.com/wfjsw/058602d9a4653a9a05d7bd873217936a/raw/artifact-patch-01.meta.js
// @downloadURL https://gist.github.com/wfjsw/058602d9a4653a9a05d7bd873217936a/raw/artifact-patch-01.user.js
// @include https://*.ingress.com/intel*
// @include http://*.ingress.com/intel*
// @match https://*.ingress.com/intel*
// @match http://*.ingress.com/intel*
// @grant none
// ==/UserScript==
// ==UserScript==
// @id iitc_patch_artifact01
// @name WFENL-Toolkit IITC plugin: Fix Artifact Target Team Recognize
// @category Hack
// @version 0.0.1.20170130.000005
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL https://gist.github.com/wfjsw/058602d9a4653a9a05d7bd873217936a/raw/artifact-patch-01.meta.js
// @downloadURL https://gist.github.com/wfjsw/058602d9a4653a9a05d7bd873217936a/raw/artifact-patch-01.user.js
// @include https://*.ingress.com/intel*
// @include http://*.ingress.com/intel*
// @match https://*.ingress.com/intel*
// @match http://*.ingress.com/intel*
// @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 START ////////////////////////////////////////////////////////
var setup = function() {
$(addHook('portalDetailLoaded', (datam) => {
console.log(datam['guid']);
try {
if (artifact.portalInfo && (datam.guid in artifact.portalInfo))
window.artifact.portalInfo[datam.guid][datam.details.artifactDetail.type].fragments = datam.details.artifactDetail.fragments;
} catch(e) {console.log(e);}
}));
// Patch processResult
window.artifact.processResult = function (portals) {
// portals is an object, keyed from the portal GUID, containing the portal entity array
var i_g = 0, seq = [];
for (var guid in portals) {
var ent = portals[guid];
var data = decodeArray.portalSummary(ent);
seq[guid] = i_g++;
// we no longer know the faction for the target portals, and we don't know which fragment numbers are at the portals
// all we know, from the portal summary data, for each type of artifact, is that each artifact portal is
// - a target portal or not - no idea for which faction
// - has one (or more) fragments, or not
if (!artifact.portalInfo[guid]) artifact.portalInfo[guid] = {};
// store the decoded data - needed for lat/lng for layer markers
artifact.portalInfo[guid]._data = data;
for(var type in data.artifactBrief.target) {
if (!artifact.artifactTypes[type]) artifact.artifactTypes[type] = {};
if (!artifact.portalInfo[guid][type]) artifact.portalInfo[guid][type] = {};
//artifact.portalInfo[guid][type].target = TEAM_NONE; // as we no longer know the team...
// No No No, Let's Just Guess.
if (/res/.test(type)) artifact.portalInfo[guid][type].target = TEAM_RES;
else if (/enl/.test(type)) artifact.portalInfo[guid][type].target = TEAM_ENL;
else artifact.portalInfo[guid][type].target = TEAM_NONE;
}
for(var type in data.artifactBrief.fragment) {
if (!artifact.artifactTypes[type]) artifact.artifactTypes[type] = {};
if (!artifact.portalInfo[guid][type]) artifact.portalInfo[guid][type] = {};
//artifact.portalInfo[guid][type].fragments = true; //as we no longer have a list of the fragments there
// We may use every bit info that we have.
var target_detail = window.portalDetail.get(guid);
if (target_detail) artifact.portalInfo[guid][type].fragments = target_detail['artifactDetail'].fragments;
//else artifact.portalInfo[guid][type].fragments = true;
else {
artifact.portalInfo[guid][type].fragments = true;
setTimeout((tguid) => {
window.portalDetail.request(tguid);
}, 4000 + seq[guid] * 2000, guid);
}
}
// let's pre-generate the entities needed to render the map - array of [guid, timestamp, ent_array]
artifact.entities.push ( [guid, data.timestamp, ent] );
}
window.artifact.showArtifactList = function() {
var html = '';
if (Object.keys(artifact.artifactTypes).length === 0) {
html += '<i>No artifacts at this time</i>';
}
var first = true;
var tableRows = [];
html += '<table class="artifact">';
html += '<tr><th>Portal</th><th>Details</th></tr>';
//$.each(artifact.artifactTypes, function(type,type2) {
// no nice way to convert the Niantic internal name into the correct display name
// (we do get the description string once a portal with that shard type is selected - could cache that somewhere?)
/*var name = type.capitalize() + ' shards';
if (!first) html += '<hr>';
first = false;
html += '<div><b>'+name+'</b></div>';
*/
$.each(artifact.portalInfo, function(guid, data) {
//if (type in data) {
// this portal has data for this artifact type - add it to the table
var onclick = 'zoomToAndShowPortal(\''+guid+'\',['+data._data.latE6/1E6+','+data._data.lngE6/1E6+'])';
var row = '<tr><td class="portal"><a onclick="'+onclick+'">['+data._data.team+']'+escapeHtmlSpecialChars(data._data.title)+'</a></td>';
row += '<td class="info">';
for(type in data){
if (data[type].target !== undefined) {
if (data[type].target == TEAM_NONE) {
row += '<span class="target">Target Portal</span> ';
} else {
row += '<span class="target '+TEAM_TO_CSS[data[type].target]+'">'+(data[type].target==TEAM_RES?'Resistance':'Enlightened')+' target</span> ';
}
}
}
for(type in data){
if (data[type].fragments) {
if (data[type].target !== undefined) {
row += '<br>';
}
var fragmentName = 'shard';
if (data[type].fragments instanceof Array) row += '<span class="fragments'+(data[type].target?' '+TEAM_TO_CSS[data[type].target]:'')+'">'+fragmentName+': #'+data[type].fragments.join(', #')+'</span> ';
else row += '<span class="fragments'+(data[type].target?' '+TEAM_TO_CSS[data[type].target]:'')+'">'+fragmentName+': yes</span> ';
}
}
row += '</td></tr>';
// sort by target portals first, then by portal GUID
var sortVal = (data[type].target !== undefined ? 'A' : 'Z') + guid;
tableRows.push ( [sortVal, row] );
//}
});
//});
// check for no rows, and add a note to the table instead
if (tableRows.length == 0) {
html += '<tr><td colspan="2"><i>No portals at this time</i></td></tr>';
}
// sort the rows
tableRows.sort(function(a,b) {
if (a[0] == b[0]) return 0;
else if (a[0] < b[0]) return -1;
else return 1;
});
// and add them to the table
html += tableRows.map(function(a){return a[1];}).join('');
html += '</table>';
html += "<hr />"
+ "<p>In Summer 2015, Niantic changed the data format for artifact portals. We no longer know:</p>"
+ "<ul><li>Which team each target portal is for - only that it is a target</li>"
+ "<li>Which shards are at each portal, just that it has one or more shards</li></ul>"
+ "<p>You can select a portal and the detailed data contains the list of shard numbers, but there's still no"
+ " more information on targets.</p>";
dialog({
title: 'Artifacts',
html: html,
width: 400,
position: {my: 'right center', at: 'center-60 center', of: window, collision: 'fit'}
});
};
};
};
// PLUGIN END //////////////////////////////////////////////////////b///
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment