IngressBuilderRevenue

Add a tool to compute the number of fields, links, points, that a player can get from a particular area.

  1. // ==UserScript==
  2. // @name IngressBuilderRevenue
  3. // @namespace notableTieView
  4. // @description Add a tool to compute the number of fields, links, points, that a player can get from a particular area.
  5. // @include https://www.ingress.com/
  6. // @version 1.0
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. // add functions and variable that are to be available on the page
  11. function wrapper() {
  12. window.toggleDisplay = function (selector) {
  13. item = $(selector);
  14. if (item.hasClass('invisible')) {
  15. item.removeClass('invisible');
  16. } else {
  17. item.addClass('invisible');
  18. }
  19. };
  20. window.addCommas = function(nStr) {
  21. nStr += '';
  22. x = nStr.split('.');
  23. x1 = x[0];
  24. x2 = x.length > 1 ? '.' + x[1] : '';
  25. var rgx = /(\d+)(\d{3})/;
  26. while (rgx.test(x1)) {
  27. x1 = x1.replace(rgx, '$1' + ',' + '$2');
  28. }
  29. return x1 + x2;
  30. };
  31. window.addLineData = function(selector, num, ap) {
  32. rowTds=$(selector);
  33. rowTds.eq(1).text(addCommas(num));
  34. rowTds.eq(2).text(addCommas(ap));
  35. };
  36. window.computeStatistics = function() {
  37. portals=parseInt($('#numPortals').val());
  38. portalsOnKonvexHull=parseInt($('#numBorder').val());
  39. if (isNaN(portals) || isNaN(portalsOnKonvexHull)) {
  40. alert("Please enter valid numbers.");
  41. return;
  42. }
  43. numFields=2*portals - portalsOnKonvexHull -2;
  44. numLinks = 3*portals -portalsOnKonvexHull -3;
  45. numResos = 8*portals;
  46. numMods = 2*portals;
  47. apFields=numFields*1250;
  48. apMods = numMods*150;
  49. apResos = numResos*125+portals*(500+250);
  50. apLinks = numLinks*313;
  51. sum=apFields+apMods+apResos+apLinks;
  52. addLineData('#ingressMods td', numMods, apMods);
  53. addLineData('#ingressResos td', numResos, apResos);
  54. addLineData('#ingressFields td', numFields, apFields);
  55. addLineData('#ingressLinks td', numLinks, apLinks);
  56. addLineData('#ingressSum td', '', sum);
  57. };
  58. // ...
  59. }
  60. var script = document.createElement('script');
  61. script.appendChild(document.createTextNode('(' + wrapper + ')();'));
  62. (document.body || document.head || document.documentElement).appendChild(script);
  63. function addGlobalStyle(css) {
  64. var head,
  65. style;
  66. head = document.getElementsByTagName('head') [0];
  67. if (!head) {
  68. return;
  69. }
  70. style = document.createElement('style');
  71. style.type = 'text/css';
  72. style.innerHTML = css;
  73. head.appendChild(style);
  74. }
  75. addGlobalStyle('.invisible { display:none !important; }');
  76. addGlobalStyle('#compute {\
  77. background-color: rgba(31,31,31,0.9);\
  78. color: rgb(17, 236, 247);\
  79. z-index: 100;\
  80. height: 320px;\
  81. margin-top: 100px;\
  82. left:50%;\
  83. width: 340px;\
  84. margin-left: -170px;\
  85. position:fixed;\
  86. padding:10px;\
  87. border-width: 1px;\
  88. border-style: solid;\
  89. font-family: coda_regular,sans-serif;\
  90. }');
  91. addGlobalStyle('#revenueButton,#intelButton {\
  92. font-size: 16px;\
  93. margin: 0.75em 0px;\
  94. padding: 0.7em 1em;\
  95. position: relative;\
  96. cursor: pointer;\
  97. font-weight: 700;\
  98. border-width: 1px;\
  99. border-style: solid;\
  100. font-family: sans-serif;\
  101. text-decoration: none;\
  102. z-index:999;\
  103. position:fixed;\
  104. right:10px;\
  105. background-color: #11ECf7;\
  106. color: black;\
  107. }');
  108.  
  109. addGlobalStyle('#intelButton {\
  110. margin-top:3.75em;\
  111. }');
  112.  
  113.  
  114. addGlobalStyle('.ingressAP {\
  115. text-align:right;\
  116. }');
  117.  
  118. addGlobalStyle('.ingressCount {\
  119. text-align:right;\
  120. }');
  121.  
  122. addGlobalStyle('#numPortals, #numBorder {\
  123. width:50px;\
  124. margin-right:10px;\
  125. }');
  126.  
  127. addGlobalStyle('#builderHeading {\
  128. font-size:2.3em;\
  129. }');
  130.  
  131. addGlobalStyle('#revenueTable {\
  132. width: 80%;\
  133. margin-left: 5%;\
  134. border-spacing: 20px 0px;\
  135. table-layout: fixed;\
  136. }');
  137.  
  138. addGlobalStyle('th {\
  139. text-align:left;\
  140. }');
  141.  
  142.  
  143. $('body').append(' <a id="revenueButton" onclick="toggleDisplay(\'#compute\')">Compute Area AP</a>');
  144. $('body').append(' <a id="intelButton" href="/intel">Intel</a>');
  145.  
  146. $('body').append('\
  147. <div id="compute" class="invisible">\
  148. <div id="builderHeading">Builder Revenue</div>\
  149. <p>Enter the number of portals in the area and the number of portals (thereof) which form the border (all other portals are inside the polygon they form).</p>\
  150. <p>\
  151. <label>Portals:</label>\
  152. <input type="number" id="numPortals"/>\
  153. <label>Border:</label>\
  154. <input type="number" id="numBorder"/>\
  155. <button type="button" id="computeButton" onclick="computeStatistics()">Compute</button>\
  156. </p>\
  157. <table id="revenueTable">\
  158. <tr>\
  159. <th class="ingressEntity">Entity</th><th class="ingressCount">Number</th><th class="ingressAP">AP</th>\
  160. </tr>\
  161. <tr id="ingressResos">\
  162. <td class="ingressEntity">Resos</td><td class="ingressCount">0</td><td class="ingressAP">0</td>\
  163. </tr>\
  164. <tr id="ingressLinks">\
  165. <td class="ingressEntity">Links</td><td class="ingressCount">0</td><td class="ingressAP">0</td>\
  166. </tr>\
  167. <tr id="ingressFields">\
  168. <td class="ingressEntity">Fields</td><td class="ingressCount">0</td><td class="ingressAP">0</td>\
  169. </tr>\
  170. <tr id="ingressMods">\
  171. <td class="ingressEntity">Mods</td><td class="ingressCount">0</td><td class="ingressAP">0</td>\
  172. </tr>\
  173. <tr id="ingressSum">\
  174. <td class="ingressEntity">Total</td><td class="ingressCount">0</td><td class="ingressAP">0</td>\
  175. </tr>\
  176. </table>\
  177. </div>'
  178. );