Created
October 22, 2017 10:32
-
-
Save isnot/c35b9b188c1b4cb7884cbf6d6b37a9bc to your computer and use it in GitHub Desktop.
IITC Plugins: portal-highlighter-missing-reso-plus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @id iitc-plugin-highlight-portals-missing-reso-plus@isnot | |
// @name IITC plugin: highlight portals missing resonators. and portal level. | |
// @category Highlighter | |
// @version 0.1.1 | |
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion | |
// @updateURL none | |
// @downloadURL none | |
// @description [iitc-plugins] Use the portal fill color to denote if the portal is missing resonators. and portal level. | |
// @auther isnot | |
// @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 //////////////////////////////////////////////////////// | |
// use own namespace for plugin | |
window.plugin.portalsMissingResoPlus = function () {}; | |
window.plugin.portalsMissingResoPlus.ENABLE_DEBUG = false; | |
window.plugin.portalsMissingResoPlus.highlight = function (data) { | |
var portal = data.portal.options, | |
res_count = 0, | |
color = '', | |
fill_opacity = 1, | |
params = {}, | |
dash; | |
if (portal.team === TEAM_NONE) { | |
return; | |
} | |
res_count = portal.data.resCount; | |
if (res_count !== undefined && res_count < 8) { | |
fill_opacity = ((8 - res_count) / 8) * 0.85 + 0.15; | |
color = '#ff4444'; // red : Missing Resonators | |
// Hole per missing resonator | |
dash = new Array((8 - res_count) + 1).join('1,4,') + '100,0'; | |
} | |
if ((res_count !== undefined) && (res_count === 8) && (portal.level >= 4)) { | |
color = '#ffe259'; // yellow : P4+ | |
fill_opacity = 0.8; | |
} | |
if (color !== '') { | |
params = {fillColor: color, fillOpacity: fill_opacity}; | |
if (dash) { | |
params.dashArray = dash; | |
} | |
data.portal.setStyle(params); | |
} | |
}; | |
var setup = function() { | |
window.addPortalHighlighter('Missing reso and P4+.', window.plugin.portalsMissingResoPlus.highlight); | |
}; | |
// 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