Skip to content

Instantly share code, notes, and snippets.

@bungasnail
Created July 3, 2016 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bungasnail/05d5d926884bc064b73a0d067c5492d7 to your computer and use it in GitHub Desktop.
Save bungasnail/05d5d926884bc064b73a0d067c5492d7 to your computer and use it in GitHub Desktop.
Highlight portals almost to L8
// ==UserScript==
// @id iitc-plugin-highlight-almost-L8@Ax238
// @name IITC plugin: Highlight portals almost to L8
// @category Highlighter
// @version 0.2.0.20150414.827
// @namespace https://github.com/
// @updateURL https://github.com/
// @downloadURL https://github.com/
// @description [Ax238-2015-04-14-000000] Highlight portals almost to L8.
// @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel*
// @match https://www.ingress.com/intel*
// @match http://www.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 ////////////////////////////////////////////////////////
// use own namespace for plugin
var thisPlugin = window.plugin.almostEight = {
setSelected: setSelected,
highlight: highlight,
onPortalDetailLoaded: onPortalDetailLoaded
};
function setSelected(selected){
thisPlugin.selected = selected;
}
function highlight(data) {
if (data.portal.options.level != 7) return;
var guid = data.portal.options.guid;
if (guid && !portalDetail.isFresh(guid)) {
portalDetail.request(guid);
// var myInterval = window.setInterval(function(){
// var details = portalDetail.get(guid);
// if(details) {
// window.clearInterval(myInterval);
// window.plugin.almostEight.updateDisplay(data.portal, details);
// }
// }, 500);
}
var details = portalDetail.get(guid);
if (details) {
updateDisplay(data.portal, details);
}
}
function onPortalDetailLoaded(data){ // guid, success, details
if (!data) return;
var details = data.details || portalDetail.get(data.guid);
if (details) {
var portal = window.portals[data.guid];
updateDisplay(portal, details);
}
}
function countUpgradableResos(details) {
var resos = $.grep(details.resonators, function(reso){
return !reso || parseInt(reso.level, 10) < 8;
});
return resos.length;
}
function hasMyResos(details){
var resos = $.grep(details.resonators, function(reso){
return reso && reso.owner == window.PLAYER.nickname;
});
return !!resos.length;
}
function updateDisplay(portal, details) {
if (!thisPlugin.selected || portal.options.level != 7) return;
var upgradesLeft = countUpgradableResos(details);
var hasMyReso = hasMyResos(details);
var myTeam = window.teamStringToId(window.PLAYER.team);
//var closeness = (8-numPortals)/8;
//var fill_opacity = closeness*.85 + .15;
//var color = 'black';
//var params = {fillColor: color, fillOpacity: fill_opacity};
var defaultColor = portal.options.team == 1 ? '#0088FF' : '#03DC03';
var color = hasMyReso ? 'yellow' : defaultColor;
var eights = 8 - upgradesLeft;
var radius = 6 + eights;
var fillColor = COLORS_LVL[eights];
var fill_opacity = 1;
var params = {color: color, fillColor: fillColor, fillOpacity: fill_opacity, radius: radius};
portal.setStyle(params);
}
var setup = function() {
window.addHook('portalDetailLoaded', window.plugin.almostEight.onPortalDetailLoaded);
window.addPortalHighlighter('Almost L8', { highlight: window.plugin.almostEight.highlight, setSelected: window.plugin.almostEight.setSelected });
}
// PLUGIN END //////////////////////////////////////////////////////////
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