Torn Set Calculator

Calculates prices of plushie and flower sets

  1. // ==UserScript==
  2. // @name Torn Set Calculator
  3. // @version 0.5c
  4. // @description Calculates prices of plushie and flower sets
  5. // @author MrHat / foilman
  6. // @namespace MrHat.Torn
  7. // @require http://cdnjs.cloudflare.com/ajax/libs/accounting.js/0.4.1/accounting.min.js
  8. // @match http://www.torn.com/imarket.php*
  9. // @match https://www.torn.com/imarket.php*
  10. // ==/UserScript==
  11.  
  12. // List item sets
  13. var itemSets = [
  14. {
  15. name: "Plushie Set",
  16. points: 10,
  17. itemIds: ["186", "215", "187", "261", "618", "258", "273", "269", "266", "268", "281", "274", "384"]
  18. }, {
  19. name: "Exotic Flower Set",
  20. points: 10,
  21. itemIds: ["260", "617", "263", "272", "264", "271", "267", "277", "282", "276", "385"]
  22. }, {
  23. name: "Medieval Coin Set",
  24. points: 100,
  25. itemIds: ["450", "451", "452"]
  26. }, {
  27. name: "Vairocana Buddha",
  28. points: 100,
  29. itemIds: ["454"]
  30. }, {
  31. name: "Ganesha Sculpture",
  32. points: 250,
  33. itemIds: ["453"]
  34. }, {
  35. name: "Shabti Sculpture",
  36. points: 500,
  37. itemIds: ["458"]
  38. }, {
  39. name: "Scripts from the Quran Set",
  40. points: 1000,
  41. itemIds: ["455", "456", "457"]
  42. }, {
  43. name: "Senet Game Set",
  44. points: 2000,
  45. itemIds: ["460", "460", "460", "460", "460", "461", "461", "461", "461", "461", "462"]
  46. }, {
  47. name: "Egyptian Amulet",
  48. points: 10000,
  49. itemIds: ["459"]
  50. }];
  51.  
  52. function itemsLoaded(items) {
  53.  
  54. // Show results on page (attempt to find container, if it's not there we create it)
  55. var container = $('#setCalculator');
  56. if (!container.length) {
  57. container = $('<div>').attr('id', 'setCalculator').addClass('msg right-round');
  58.  
  59. var wrapper = $('<div>').addClass('info-msg border-round').html($('<i>').addClass('info-icon'));
  60. wrapper.append(container);
  61. wrapper.prependTo($('.main-market-page'));
  62. }
  63.  
  64. // Clear text
  65. container.empty();
  66.  
  67. // Loop over itemsets and create a result message
  68. var setResults = [];
  69.  
  70. $.each(itemSets, function(i, itemSet) {
  71. var sum = 0;
  72. $.each(items, function(j, item) {
  73.  
  74. // Lookup how many times this item is required in this given set
  75. var occurence = $.grep(itemSet.itemIds, function (itemId) {
  76. return itemId === item.itemID;
  77. }).length;
  78.  
  79. // We add the total price for this item
  80. sum += (parseInt(item.price) * occurence);
  81. });
  82.  
  83. if (sum > 0) {
  84.  
  85. setResults.push({
  86. set: itemSet,
  87. totalCost: sum,
  88. individualCost: sum/itemSet.points
  89. });
  90. }
  91. });
  92.  
  93. // Show message on page
  94. if (setResults.length) {
  95.  
  96. // Sort sets from cheap to expensive
  97. var sortedResults = setResults.sort(function(a, b) {
  98. return a.individualCost > b.individualCost;
  99. });
  100.  
  101. // Generate final message
  102. var message = sortedResults.map(function(setResult) {
  103. return "One " + setResult.set.name + " costs <b>" + accounting.formatMoney(setResult.totalCost, "$", 0) + "</b>. This equals to <b>" + accounting.formatMoney(setResult.individualCost, "$", 0) + "</b> per point.<br/>";
  104. });
  105.  
  106. // Append the message to the container
  107. container.append($('<span>').html(message));
  108. } else {
  109.  
  110. // No sets were present on this page
  111. container.append($('<span>').html('No sets available.'));
  112. }
  113. };
  114.  
  115. $(document).ajaxComplete(function(e,xhr,settings){
  116. var marketRegex = /^imarket.php\?rfcv=(.+)$/;
  117. if (marketRegex.test(settings.url)) {
  118.  
  119. // Process the items and their prices
  120. var items = JSON.parse(xhr.responseText);
  121. if (items) itemsLoaded(items);
  122. }
  123. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址