Forked from bungasnail/Highlight plrtals almost to L8
Last active
August 14, 2021 15:10
-
-
Save ryantheleach/e7d730e43d648bb59baff2698499c743 to your computer and use it in GitHub Desktop.
Highlight portals almost to L8
This file contains hidden or 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-resonator-L8-count@RTL | |
// @name IITC plugin: Highlight portals based on number of 8's | |
// @category Highlighter | |
// @version 1.0.0.20200705.1450 | |
// @namespace https://github.com/ | |
// @updateURL https://github.com/ | |
// @downloadURL https://github.com/ | |
// @description Highlight portals based on number of level 8 resonators. | |
// @include https://www.ingress.com/intel* | |
// @include http://www.ingress.com/intel* | |
// @match https://www.ingress.com/intel* | |
// @match http://www.ingress.com/intel* | |
// @include https://intel.ingress.com/* | |
// @match https://intel.ingress.com/* | |
// @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 | |
}; | |
const EIGHT_CAP = 1; | |
window.plugin.almostEight.dash = function(res_count, radius){ | |
var circumference = radius*6; | |
var spacer = circumference/32; | |
var dash = spacer*3; | |
return new Array((8 - res_count+1)).join(spacer+','+dash+',') + '1000'; | |
} | |
function setSelected(selected){ | |
thisPlugin.selected = selected; | |
} | |
function highlight(data) { | |
//if (data.portal.options.level < 6) return; | |
var guid = data.portal.options.guid; | |
if (guid && !portalDetail.isFresh(guid)) { | |
portalDetail.request(guid); | |
} | |
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); | |
} | |
} | |
// counts number of resonator that are less then 8. | |
function countUpgradableResos(details) { | |
var resos = $.grep(details.resonators, function(reso){ | |
return reso && parseInt(reso.level, 10) < 8; | |
}); | |
return resos.length + (8-details.resonators.length); | |
} | |
// counts the amount of upgrades remaining. | |
function myUpgradesAvailable(portal, details){ | |
//BUG: DOES NOT TAKE TEAMS INTO ACCOUNT. | |
var myTeam = window.teamStringToId(window.PLAYER.team); | |
var portalTeam = portal.options.team; | |
if(portalTeam != myTeam) return 0; | |
var resos = $.grep(details.resonators, function(reso){ | |
return reso && reso.owner == window.PLAYER.nickname; | |
}); | |
var myEightCount = resos.length; | |
var teamUpgradesAvailable = countUpgradableResos(details); | |
var myMaxUpgrades = Math.min(teamUpgradesAvailable, EIGHT_CAP); | |
return Math.max(0, myMaxUpgrades - myEightCount); | |
} | |
function updateDisplay(portal, details) { | |
//if (!thisPlugin.selected || portal.options.level < 6) return; | |
var upgradesLeft = countUpgradableResos(details); | |
var myUpgradeCount = myUpgradesAvailable(portal, details); | |
var myTeam = window.teamStringToId(window.PLAYER.team); | |
var defaultColor = COLORS[portal.options.team]; | |
var color = myUpgradeCount > 0 ? 'yellow' : defaultColor; | |
var eights = 8 - upgradesLeft; | |
var afterUpgrade = Math.min(8, eights + myUpgradeCount); | |
var radius = 6 + eights*1.5; | |
var fillColor = portal.options.level == 8 ? 'black' : COLORS_LVL[afterUpgrade]; | |
fillColor = afterUpgrade == 0 ? COLORS[0] : fillColor; | |
var fill_opacity = (eights + EIGHT_CAP)/16+0.5; | |
var params = {color: color, fillColor: fillColor, fillOpacity: fill_opacity, radius: radius, weight:fill_opacity*4, dashArray:window.plugin.almostEight.dash(eights, 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