Advertisement
Guest User

IITC highlight plugin example - more fields than links

a guest
Apr 17th, 2015
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @id             iitc-plugin-highlight-portals-missing-resonators@vita10gy
  3. // @name           IITC plugin: highlight portals with more fields than links
  4. // @category       Highlighter
  5. // @version        0.1.2.20150414.12303
  6. // @namespace      https://github.com/jonatkins/ingress-intel-total-conversion
  7. // @description    [jonatkins-test-2015-04-14-012303] Use the portal fill color to denote if the portal has more fields than links.
  8. // @include        https://www.ingress.com/intel*
  9. // @include        http://www.ingress.com/intel*
  10. // @match          https://www.ingress.com/intel*
  11. // @match          http://www.ingress.com/intel*
  12. // @include        https://www.ingress.com/mission/*
  13. // @include        http://www.ingress.com/mission/*
  14. // @match          https://www.ingress.com/mission/*
  15. // @match          http://www.ingress.com/mission/*
  16. // @grant          none
  17. // ==/UserScript==
  18.  
  19.  
  20. function wrapper(plugin_info) {
  21. // ensure plugin framework is there, even if iitc is not yet loaded
  22. if(typeof window.plugin !== 'function') window.plugin = function() {};
  23.  
  24.  
  25. // PLUGIN START ////////////////////////////////////////////////////////
  26.  
  27. // use own namespace for plugin
  28. window.plugin.portalsMoreFeldsThanLinks = function() {};
  29.  
  30.  
  31. window.plugin.portalsMoreFeldsThanLinks.highlight = function(data) {
  32.   var fill_opacity = 0.7;
  33.   var color = undefined;
  34.   var portalLinksCount = -1;
  35.   var portalFieldsCount = -1;
  36.  
  37.   // Totally wrong? Always returns 0 as result ...
  38.   portalLinksCount = window.getPortalLinksCount(data.portal.options.guid);
  39.   portalFieldsCount = window.getPortalFieldsCount(data.portal.options.guid);
  40.  
  41.   // Debug (see comment above)
  42.   console.log("portalLinksCount: %d", portalLinksCount);
  43.   console.log("portalFieldsCount: %d", portalFieldsCount);
  44.  
  45.   if(data.portal.options.team != TEAM_NONE) {
  46.     if(portalFieldsCount > portalLinksCount) {
  47.       var color = 'red';
  48.       var params = {fillColor: color, fillOpacity: fill_opacity};
  49.  
  50.       data.portal.setStyle(params);
  51.     }
  52.   }
  53. }
  54.  
  55. window.plugin.portalsMoreFeldsThanLinks.highlight.setSelected = function(selected) {
  56.   window.plugin.portalsMoreFeldsThanLinks.isSelected=selected;
  57. }
  58.  
  59. window.plugin.portalsMoreFeldsThanLinks.mapRefreshEnd = function() {
  60.   if (window.plugin.portalsMoreFeldsThanLinks.isSelected) {
  61.     resetHighlightedPortals();
  62.   }
  63. }
  64.  
  65. var setup =  function() {
  66.   window.plugin.portalsMoreFeldsThanLinks.isSelected = false;
  67.   window.addPortalHighlighter('Portals With More Fields than Links', window.plugin.portalsMoreFeldsThanLinks.highlight);
  68.  
  69. }
  70.  
  71. // PLUGIN END //////////////////////////////////////////////////////////
  72.  
  73.  
  74. setup.info = plugin_info; //add the script info data to the function as a property
  75. if(!window.bootPlugins) window.bootPlugins = [];
  76. window.bootPlugins.push(setup);
  77. // if IITC has already booted, immediately run the 'setup' function
  78. if(window.iitcLoaded && typeof setup === 'function') setup();
  79. } // wrapper end
  80. // inject code into site context
  81. var script = document.createElement('script');
  82. var info = {};
  83. 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 };
  84. script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));
  85. (document.body || document.head || document.documentElement).appendChild(script);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement