Steam Item Price Averager

Takes the average of the last 10 items sold of the current item

  1. // ==UserScript==
  2. // @name Steam Item Price Averager
  3. // @namespace https://gf.qytechs.cn/scripts/4219-steam-item-price-averager
  4. // @version 1.1
  5. // @description Takes the average of the last 10 items sold of the current item
  6. // @include http://steamcommunity.com/market/*
  7. // @require http://code.jquery.com/jquery-latest.js
  8. // @copyright 2014, Nate
  9. // ==/UserScript==
  10.  
  11. $(document).ready(function() {
  12. // Add table header
  13. $("#searchResults").find(".market_listing_table_header").first().children(".market_listing_right_cell").last().after('<div class="market_listing_right_cell" style="padding: 0 0.5em">AVG. PRICE</div>');
  14. $("#sellListings").find(".market_listing_table_header").first().children(".market_listing_right_cell").last().after('<div class="market_listing_right_cell" style="padding: 0 0.5em">AVG. PRICE</div>');
  15. var url = window.location.pathname;
  16. var pageType = getPageType(url);
  17. //console.log(url);
  18. if (pageType == "item") {
  19. var item = $(".market_listing_nav a:last-child").html();
  20. new Ajax.Request( 'http://steamcommunity.com/market/pricehistory/', {
  21. method: 'get',
  22. parameters: {
  23. appid: getAppIDItem(url),
  24. market_hash_name: item
  25. },
  26. onSuccess: function( transport ) { sumAverage(transport) },
  27. onFailure: function( transport ) { failed() }
  28. } );
  29. } else if (pageType == "search") {
  30. // Get average price for each item
  31. $('#searchResults').find('.market_listing_item_name').each(function() {
  32. var item = $(this).text();
  33. var currItem = this;
  34. new Ajax.Request( 'http://steamcommunity.com/market/pricehistory/', {
  35. method: 'get',
  36. parameters: {
  37. appid: getAppIDMulti(this),
  38. market_hash_name: item
  39. },
  40. onSuccess: function( transport ) { sumAverage(transport, currItem, item) },
  41. onFailure: function( transport ) { failed(item) }
  42. } );
  43. });
  44. } else {
  45. // Get average price for each item
  46. $('#sellListings').find('.market_listing_item_name').each(function() {
  47. var item = $(this).text();
  48. var currItem = this;
  49. new Ajax.Request( 'http://steamcommunity.com/market/pricehistory/', {
  50. method: 'get',
  51. parameters: {
  52. appid: getAppIDMulti(this),
  53. market_hash_name: item
  54. },
  55. onSuccess: function( transport ) { sumAverage(transport, currItem, item) },
  56. onFailure: function( transport ) { failed(item) }
  57. } );
  58. });
  59. }
  60. function getPageType(url) {
  61. var splitURL = url.split("/");
  62. var pageType = splitURL[2];
  63. //console.log(pageType);
  64. if (pageType == "listings") {
  65. //console.log("item");
  66. return "item";
  67. } else if (pageType == "search") {
  68. //console.log("search");
  69. return "search";
  70. } else {
  71. //console.log("main");
  72. return "main";
  73. }
  74. }
  75. function getAppIDMulti(elem) {
  76. var a = $(elem).parent().parent().parent().attr('href');
  77. //console.log(a);
  78. var url = a.split("/");
  79. var appid = url[5];
  80. //console.log(appid);
  81. return appid;
  82. }
  83. function getAppIDItem(url) {
  84. var splitURL = url.split("/");
  85. var appid = splitURL[3];
  86. //console.log(appid);
  87. return appid;
  88. }
  89. function failed() {
  90. console.log("Could not get price history for " + item);
  91. }
  92. function sumAverage(transport, currItem, item) {
  93. // JSON
  94. var results = transport.responseText;
  95. // Print results - debugging
  96. //console.log(results);
  97. // Parse JSON
  98. var parsed = JSON.parse(results);
  99. // Store in array
  100. var arr = $.map(parsed, function(el) { return el; });
  101.  
  102. // Number of sales
  103. //console.log(arr.length);
  104. // Variables
  105. var total = 0;
  106. var count = 10;
  107. for (var i=arr.length-1; i >= arr.length - count;i--) {
  108. // Get sale price
  109. var val = arr[i][1];
  110. // Add to total
  111. total = total + val
  112. // Value output - debugging
  113. //console.log("VALUE " + val);
  114. }
  115. // Calculate average
  116. var avg = parseFloat(total/count).toFixed(2);
  117. // Average output - debugging
  118. //console.log("AVERAGE " + avg);
  119. if (pageType == "item") {
  120. // Show on page
  121. $(".item_desc_content").append('<div class="average_price" style="font-size: 1.2em"> Average price: <span style="font-size: 1.75em">$' + avg + '</span></div>');
  122. } else {
  123. // Show on page
  124. $(currItem).parent().parent().children(".market_listing_right_cell").last().after('<div class="market_listing_right_cell average_price" style="text-align: center; width: 80px"><span class="market_table_value" style="padding: 0 0.5em">$' + avg + '</span></span></div>');
  125. }
  126. }
  127. });

QingJ © 2025

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