Resource Value Saver

Store resource values from the ticker for calculation in other scripts

  1. // ==UserScript==
  2. // @name Resource Value Saver
  3. // @namespace http://www.knightsradiant.pw
  4. // @version 0.11
  5. // @description Store resource values from the ticker for calculation in other scripts
  6. // @author Talus
  7. // @match https://politicsandwar.com/index.php?id=26*
  8. // @require https://code.jquery.com/jquery-3.6.0.min.js
  9. // @license GPL-3.0-or-later
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function(){
  14. var tickerSelectPath = '#rightcolumn > p.alert.alert-warning > marquee';
  15. var resourceRE = /Food: \$(?<food>[\d,]+) Steel: \$(?<steel>[\d,]+) Aluminum: \$(?<aluminum>[\d,]+) Munitions: \$(?<munitions>[\d,]+) Gasoline: \$(?<gasoline>[\d,]+) Coal: \$(?<coal>[\d,]+) Oil: \$(?<oil>[\d,]+) Uranium: \$(?<uranium>[\d,]+) Iron: \$(?<iron>[\d,]+) Bauxite: \$(?<bauxite>[\d,]+) Lead: \$(?<lead>[\d,]+) Credits: \$(?<credits>[\d,]+)/;
  16. var $ = window.jQuery;
  17. var tickerText = $(tickerSelectPath).text();
  18. var resourceValues = tickerText.match(resourceRE).groups;
  19. for (const property in resourceValues) {
  20. resourceValues[property] = resourceValues[property].replaceAll(',','');
  21. }
  22. localStorage.setItem('resourceValues', JSON.stringify(resourceValues));
  23. })();