Advertisement
ghost2devil

Script Price Listing

Feb 29th, 2016
6,220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.99 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Better Buy Orders
  3. // @author Stepan Fedorko-Bartos, Step7750
  4. // @namespace
  5. // @version 1.4.1
  6. // @description Improves Steam market buy orders (hot-swap view currency changing and extended listings)
  7. // @match http://steamcommunity.com/market/listings/*
  8. // @match https://steamcommunity.com/market/listings/*
  9. // @copyright 2015+, Stepan Fedorko-Bartos
  10. // @run-at document-body
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14.  
  15. // Changelog can be found at: https://github.com/Step7750/BetterBuyOrders
  16.  
  17.  
  18. window.bbo_buy_enable = 0;
  19. window.bbo_sell_enable = 0;
  20. window.itemid = null;
  21. window.show_tables = 0;
  22. window.editeddom = 0;
  23. window.nolistings = 0;
  24. window.proccessed_order = 0;
  25.  
  26. // We need to replace some page functions immediately after the body is loaded
  27. beforescript();
  28.  
  29. // Execute main_execute after full page load (added readyState for Mac systems etc...)
  30. if (document.readyState == 'complete') {
  31. if (editeddom == 0) {
  32. main_execute();
  33. }
  34. }
  35. else {
  36. if (editeddom == 0) {
  37. window.addEventListener ("load", main_execute, false);
  38. }
  39. }
  40.  
  41. function Chrome_extension_update(page_type) {
  42. // prompts the user to install the up to date extension if on chrome
  43. if (!!window.chrome == true && localStorage.getItem("dismiss_bbo_update") != "true") {
  44. if (page_type == "item") {
  45. $J("#searchResultsTable").prepend('<div id="bbo_update_dialog" class="market_listing_row" style="font-size: 18px; padding-top: 10px; padding-left: 10px; padding-bottom: 10px; font-family: Motiva Sans Light, Arial, Helvetica, sans-serif;"><div><div><div style="color: white; display: inline-block"><strong>Better Buy Orders</strong></div> is now a native Chrome extension (with more features)! <a href="https://chrome.google.com/webstore/detail/better-buy-orders/fdohejjlbpikihghncmaejajdbpoiebj">Click here to view it</a><br><div style="font-size: 14px; margin-top: 5px;">You\'ll want to remove this old script first!</div></div></div><div style="font-size: 14px; margin-top: 10px; cursor: pointer; color: white; text-decoration: underline;"><span onclick="$J(\'#bbo_update_dialog\').slideUp(); localStorage.setItem(\'dismiss_bbo_update\', true)">Don\'t show this again :(</span></div></div>');
  46. }
  47. else if (page_type == "commodity") {
  48. $J(".market_commodity_order_block").prepend('<div id="bbo_update_dialog" class="market_listing_row" style="font-size: 18px; padding-top: 10px; padding-left: 10px; padding-bottom: 10px; font-family: Motiva Sans Light, Arial, Helvetica, sans-serif;"><div><div><div style="color: white; display: inline-block"><strong>Better Buy Orders</strong></div> is now a native Chrome extension (with more features)! <a href="https://chrome.google.com/webstore/detail/better-buy-orders/fdohejjlbpikihghncmaejajdbpoiebj">Click here to view it</a><br><div style="font-size: 14px; margin-top: 5px;">You\'ll want to remove this old script first!</div></div></div><div style="font-size: 14px; margin-top: 10px; cursor: pointer; color: white; text-decoration: underline;"><span onclick="$J(\'#bbo_update_dialog\').slideUp(); localStorage.setItem(\'dismiss_bbo_update\', true)">Don\'t show this again :(</span></div></div>');
  49. }
  50. }
  51. }
  52.  
  53. function no_orders_no_listings() {
  54. if (window.proccessed_order == 0) {
  55. // this appears to be an item with no market listings and no current buy orders, we don't have the URL, but we can find some info about it
  56. console.log("Item with no listings and no buy orders")
  57.  
  58. var itemname = escapeHtml('"' + $J(".market_listing_nav a").eq(1).text().replace("★", "\\u2605").replace("™", "\\u2122") + '"');
  59. console.log(itemname);
  60. $J("#searchResultsTable").prepend('<div id="market_buyorder_info" class="market_listing_row"><div><div style="float: right"><a class="btn_green_white_innerfade btn_medium" href="javascript:void(0)" onclick="Market_ShowBuyOrderPopup( 730, ' + itemname + ', ' + itemname + '); return false;"><span>Place buy order...</span></a></div><div id="market_commodity_buyrequests"><span class="market_commodity_orders_header_promote">0</span> requests to buy at <span class="market_commodity_orders_header_promote">0.00</span> or lower</div></div><div id="market_buyorder_info_show_details"><span onclick="$J(\'#market_buyorder_info_show_details\').hide(); $J(\'#market_buyorder_info_details\').show();"> View more details </span></div><div id="market_buyorder_info_details" style="display: none;"><div id="market_buyorder_info_details_tablecontainer" style="padding-left: 10px; padding-right: 15px;"><div id="market_commodity_buyreqeusts_table" class="market_commodity_orders_table_container"></div><center><div class="btn_grey_black btn_medium" id="show_more_buy" style="margin-bottom: 10px;" onclick="toggle_state(0)"><span>Show More Orders <span class="popup_menu_pulldown_indicator" id="arrow_buy_button"></span></span></div></center></div><div id="market_buyorder_info_details_explanation"><p>You can place an order to buy at a specific price, and the cheapest listing will automatically get matched to the highest buy order.</p><p>For this item, buy orders will be matched with the cheapest option to buy regardless of any unique characteristics.</p><p>If you\'re looking for a specific characteristic, you can search or view the individual listings below.</p></div></div></div>')
  61. }
  62. }
  63.  
  64. function main_execute() {
  65.  
  66. if ($J(".market_commodity_order_block").length > 0) {
  67. // Injects the hot-swap currency selector for commodity items
  68. $J(".market_commodity_order_block").children().eq(1).after('<select id="currency_buyorder" style="margin-left: 10px; margin-bottom: 5px;"><option value="1" selected>USD</option><option value="2">GBP</option><option value="3">EUR</option><option value="5">RUB</option><option value="7">BRL</option><option value="8">JPY</option><option value="9">NOK</option><option value="10">IDR</option><option value="11">MYR</option><option value="12">PHP</option><option value="13">SGD</option><option value="14">THB</option><option value="15">VND</option><option value="16">KRW</option><option value="17">TRY</option><option value="18">UAH</option><option value="19">MXN</option><option value="20">CAD</option><option value="21">AUD</option><option value="22">NZD</option></select>');
  69. }
  70. else if ($J("#market_buyorder_info_details_tablecontainer").length > 0 && window.nolistings == 0) {
  71. // append the currency selector for weapon pages (with listings)
  72. Chrome_extension_update("item")
  73. $J("#market_buyorder_info_details_tablecontainer").prepend('<select id="currency_buyorder" style="margin-left: 15px; margin-top: 10px;"><option value="1" selected="">USD</option><option value="2">GBP</option><option value="3">EUR</option><option value="5">RUB</option><option value="7">BRL</option><option value="8">JPY</option><option value="9">NOK</option><option value="10">IDR</option><option value="11">MYR</option><option value="12">PHP</option><option value="13">SGD</option><option value="14">THB</option><option value="15">VND</option><option value="16">KRW</option><option value="17">TRY</option><option value="18">UAH</option><option value="19">MXN</option><option value="20">CAD</option><option value="21">AUD</option><option value="22">NZD</option></select>')
  74. }
  75. // set the proper value for the currency selector
  76. $J("#currency_buyorder").val(typeof( g_rgWalletInfo ) != 'undefined' && g_rgWalletInfo['wallet_currency'] != 0 ? g_rgWalletInfo['wallet_currency'] : 1);
  77.  
  78. // bind event handler to currency selector
  79. $J('#currency_buyorder').on('change', function() {
  80. if (typeof buyordertimeout !== 'undefined') {
  81. clearTimeout(buyordertimeout);
  82. }
  83. if ((ItemActivityTicker.m_llItemNameID != null && $J(".market_commodity_order_block").length > 0)) {
  84. Market_LoadOrderSpread(ItemActivityTicker.m_llItemNameID);
  85. // update item activity
  86. ItemActivityTicker.Load();
  87. }
  88. else if ($J("#market_buyorder_info_details_tablecontainer").length > 0 && itemid != null) {
  89. Market_LoadOrderSpread(itemid);
  90. }
  91. });
  92.  
  93. // Start up the request if it is a commodity page
  94. if (ItemActivityTicker.m_llItemNameID != null) {
  95. Market_LoadOrderSpread(ItemActivityTicker.m_llItemNameID);
  96. }
  97.  
  98. // add toggle buttons for commodity or item pages
  99. if (ItemActivityTicker.m_llItemNameID != null) {
  100. // Toggle buttons
  101. Chrome_extension_update("commodity")
  102. $J(".market_commodity_orders_interior").eq(1).append('<div class="btn_grey_black btn_medium" id="show_more_buy" style="margin-bottom: 10px;" onclick="toggle_state(0)"><span>Show More Orders <span class="popup_menu_pulldown_indicator" id="arrow_buy_button"></span></span></div>');
  103.  
  104. $J(".market_commodity_orders_interior").eq(0).append('<div class="btn_grey_black btn_medium" id="show_more_sell" style="margin-bottom: 10px;" onclick="toggle_state(1)"><span>Show More Orders <span class="popup_menu_pulldown_indicator" id="arrow_buy_button"></span></span></div>');
  105. }
  106. else if (window.nolistings == 0) {
  107. // buttons for item pages with listings
  108. $J("#market_buyorder_info_details_tablecontainer").append('<center><div class="btn_grey_black btn_medium" id="show_more_buy" style="margin-bottom: 10px;" onclick="toggle_state(0)"><span>Show More Orders <span class="popup_menu_pulldown_indicator" id="arrow_buy_button"></span></span></div></center>');
  109. }
  110.  
  111.  
  112. window.editeddom = 1
  113.  
  114. console.log('%c Better Buy Orders (v1.4 BETA) by Step7750 ', 'background: #222; color: #fff;');
  115. console.log('%c Changelog can be found here: https://github.com/Step7750/BetterBuyOrders', 'background: #222; color: #fff;')
  116.  
  117. no_orders_no_listings();
  118. }
  119.  
  120. function beforescript() {
  121. // Replace these functions with versions that work with items with no listings, these may break if Valve starts changing them up
  122. // Some of the main dom monipulation functions have also been moved here since we didn't want to wait for the subsequent call for updated tables
  123.  
  124. function Chrome_extension_update(page_type) {
  125. // prompts the user to install the up to date extension for chrome
  126. if (!!window.chrome == true && localStorage.getItem("dismiss_bbo_update") != "true") {
  127. if (page_type == "item") {
  128. $J("#searchResultsTable").prepend('<div id="bbo_update_dialog" class="market_listing_row" style="font-size: 18px; padding-top: 10px; padding-left: 10px; padding-bottom: 10px; font-family: Motiva Sans Light, Arial, Helvetica, sans-serif;"><div><div><div style="color: white; display: inline-block"><strong>Better Buy Orders</strong></div> is now a native Chrome extension (with more features)! <a href="https://chrome.google.com/webstore/detail/better-buy-orders/fdohejjlbpikihghncmaejajdbpoiebj">Click here to view it</a><br><div style="font-size: 14px; margin-top: 5px;">You\'ll want to remove this old script first!</div></div></div><div style="font-size: 14px; margin-top: 10px; cursor: pointer; color: white; text-decoration: underline;"><span onclick="$J(\'#bbo_update_dialog\').slideUp(); localStorage.setItem(\'dismiss_bbo_update\', true)">Don\'t show this again :(</span></div></div>');
  129. }
  130. else if (page_type == "commodity") {
  131. $J(".market_commodity_order_block").prepend('<div id="bbo_update_dialog" class="market_listing_row" style="font-size: 18px; padding-top: 10px; padding-left: 10px; padding-bottom: 10px; font-family: Motiva Sans Light, Arial, Helvetica, sans-serif;"><div><div><div style="color: white; display: inline-block"><strong>Better Buy Orders</strong></div> is now a native Chrome extension (with more features)! <a href="https://chrome.google.com/webstore/detail/better-buy-orders/fdohejjlbpikihghncmaejajdbpoiebj">Click here to view it</a><br><div style="font-size: 14px; margin-top: 5px;">You\'ll want to remove this old script first!</div></div></div><div style="font-size: 14px; margin-top: 10px; cursor: pointer; color: white; text-decoration: underline;"><span onclick="$J(\'#bbo_update_dialog\').slideUp(); localStorage.setItem(\'dismiss_bbo_update\', true)">Don\'t show this again :(</span></div></div>');
  132. }
  133. }
  134. }
  135.  
  136. function toggle_state(type) {
  137. // 0 = buy table, 1 = sell table
  138. // Called by the respective buttons
  139.  
  140. if (type == 0) {
  141. // Valve's spelling error
  142. $J("#market_commodity_buyreqeusts_table").slideUp('fast', function () {
  143. if(bbo_buy_enable == 1) {
  144. bbo_buy_enable = 0;
  145. $J("#show_more_buy").children().eq(0).html('Show More Orders <span class="popup_menu_pulldown_indicator" id="arrow_sell_button">');
  146. }
  147. else {
  148. bbo_buy_enable = 1;
  149. $J("#show_more_buy").children().eq(0).html('Show Less Orders <span class="popup_menu_pulldown_indicator" id="arrow_sell_button" style="-webkit-transform: rotate(-180deg); -ms-transform: rotate(-180deg); transform: rotate(-180deg);">');
  150. }
  151. if (typeof buyordertimeout !== 'undefined') {
  152. clearTimeout(buyordertimeout);
  153. }
  154. show_tables = 1;
  155. Market_LoadOrderSpread(ItemActivityTicker.m_llItemNameID)
  156. });
  157. }
  158. else {
  159. $J("#market_commodity_forsale_table").slideUp('fast', function () {
  160. if(bbo_sell_enable == 1) {
  161. bbo_sell_enable = 0;
  162. $J("#show_more_sell").children().eq(0).html('Show More Orders <span class="popup_menu_pulldown_indicator" id="arrow_sell_button">');
  163. }
  164. else {
  165. bbo_sell_enable = 1;
  166. $J("#show_more_sell").children().eq(0).html('Show Less Orders <span class="popup_menu_pulldown_indicator" id="arrow_sell_button" style="-webkit-transform: rotate(-180deg); -ms-transform: rotate(-180deg); transform: rotate(-180deg);">');
  167. }
  168. if (typeof buyordertimeout !== 'undefined') {
  169. clearTimeout(buyordertimeout);
  170. }
  171. show_tables = 1;
  172. // Updated the call to just show the tables if needed within the construction function
  173. Market_LoadOrderSpread(ItemActivityTicker.m_llItemNameID)
  174. });
  175. }
  176. }
  177.  
  178. function escapeHtml(text) {
  179. // escape any messed up item names (prevent cross scripting)
  180. return text
  181. .replace(/&/g, "&amp;")
  182. .replace(/</g, "&lt;")
  183. .replace(/>/g, "&gt;")
  184. .replace(/"/g, "&quot;")
  185. .replace(/'/g, "&#039;");
  186. }
  187.  
  188. // Overwrites Valve's function here: http://steamcommunity-a.akamaihd.net/public/javascript/market.js
  189. function Market_LoadOrderSpread( item_nameid )
  190. {
  191. window.proccessed_order = 1
  192. if (item_nameid == null) {
  193. item_nameid = window.itemid;
  194. }
  195. else {
  196. window.itemid = item_nameid;
  197. }
  198. $J.ajax( {
  199. url: window.location.protocol + '//steamcommunity.com/market/itemordershistogram',
  200. type: 'GET',
  201. data: {
  202. country: g_strCountryCode,
  203. language: g_strLanguage,
  204. currency: $J("#currency_buyorder").val() || (typeof( g_rgWalletInfo ) != 'undefined' && g_rgWalletInfo['wallet_currency'] != 0 ? g_rgWalletInfo['wallet_currency'] : 1),
  205. item_nameid: item_nameid,
  206. two_factor: BIsTwoFactorEnabled() ? 1 : 0
  207. }
  208. } ).error( function ( ) {
  209. window.buyordertimeout = setTimeout( function() { Market_LoadOrderSpread( item_nameid ); }, 5000 );
  210. } ).success( function( data ) {
  211. window.buyordertimeout = setTimeout( function() { Market_LoadOrderSpread( item_nameid ); }, 5000 );
  212.  
  213. if ( data.success == 1 )
  214. {
  215. // Better Buy Orders
  216.  
  217. if (document.getElementById("market_commodity_buyrequests") == null && ItemActivityTicker.m_llItemNameID == null) {
  218. // set that we have a item with no listings (to prevent other dom manipulations)
  219. if (window.nolistings == 0) {
  220. $J("#pricehistory").css("margin-bottom", "10px");
  221. $J("#searchResultsTable").append('<div class="zoom_controls pricehistory_zoom_controls" style="margin-bottom: 10px; margin-top: 10px;">Zoom graph<a class="zoomopt" onclick="return pricehistory_zoomDays( g_plotPriceHistory, g_timePriceHistoryEarliest, g_timePriceHistoryLatest, 7 );" href="javascript:void(0)">Week</a><a class="zoomopt" onclick="return pricehistory_zoomDays( g_plotPriceHistory, g_timePriceHistoryEarliest, g_timePriceHistoryLatest, 30 );" href="javascript:void(0)">Month</a><a class="zoomopt" onclick="return pricehistory_zoomLifetime( g_plotPriceHistory, g_timePriceHistoryEarliest, g_timePriceHistoryLatest );" href="javascript:void(0)" style="padding-right: 0">Lifetime</a></div>')
  222. }
  223. window.nolistings = 1;
  224.  
  225. // need to clear the waiting dialog
  226. $J("#market_buyorder_info").remove();
  227.  
  228. // need to find out the item name and append it
  229. // We're escaping the text jic Valve changes how they escape the specific area where we get the item name (prevent xss)
  230. var itemname = escapeHtml('"' + $J(".market_listing_nav a").eq(1).text().replace("★", "\\u2605").replace("™", "\\u2122") + '"');
  231. $J("#searchResultsTable").prepend('<div id="market_buyorder_info" class="market_listing_row"><div><div style="float: right"><a class="btn_green_white_innerfade btn_medium" href="javascript:void(0)" onclick="Market_ShowBuyOrderPopup( 730, ' + itemname + ', ' + itemname + '); return false;"><span>Place buy order...</span></a></div><div id="market_commodity_buyrequests"><span class="market_commodity_orders_header_promote">1684</span> requests to buy at <span class="market_commodity_orders_header_promote">CDN$ 6.72</span> or lower</div></div><div id="market_buyorder_info_show_details"><span onclick="$J(\'#market_buyorder_info_show_details\').hide(); $J(\'#market_buyorder_info_details\').show();"> View more details </span></div><div id="market_buyorder_info_details" style="display: none;"><div id="market_buyorder_info_details_tablecontainer" style="padding-left: 10px; padding-right: 15px;"><div id="market_commodity_buyreqeusts_table" class="market_commodity_orders_table_container"></div><center><div class="btn_grey_black btn_medium" id="show_more_buy" style="margin-bottom: 10px;" onclick="toggle_state(0)"><span>Show More Orders <span class="popup_menu_pulldown_indicator" id="arrow_buy_button"></span></span></div></center></div><div id="market_buyorder_info_details_explanation"><p>You can place an order to buy at a specific price, and the cheapest listing will automatically get matched to the highest buy order.</p><p>For this item, buy orders will be matched with the cheapest option to buy regardless of any unique characteristics.</p><p>If you\'re looking for a specific characteristic, you can search or view the individual listings below.</p></div></div></div>')
  232.  
  233. // append and configure the currency selector
  234. $J("#market_buyorder_info_details_tablecontainer").prepend('<select id="currency_buyorder" style="margin-left: 5px; margin-top: 10px;"><option value="1" selected>USD</option><option value="2">GBP</option><option value="3">EUR</option><option value="5">RUB</option><option value="7">BRL</option><option value="8">JPY</option><option value="9">NOK</option><option value="10">IDR</option><option value="11">MYR</option><option value="12">PHP</option><option value="13">SGD</option><option value="14">THB</option><option value="15">VND</option><option value="16">KRW</option><option value="17">TRY</option><option value="18">UAH</option><option value="19">MXN</option><option value="20">CAD</option><option value="21">AUD</option><option value="22">NZD</option></select>');
  235. $J("#currency_buyorder").val(typeof( g_rgWalletInfo ) != 'undefined' && g_rgWalletInfo['wallet_currency'] != 0 ? g_rgWalletInfo['wallet_currency'] : 1);
  236.  
  237. // Bind the currency selector event handler
  238. $J('#currency_buyorder').on('change', function() {
  239. clearTimeout(buyordertimeout);
  240. if (itemid != null) {
  241. Market_LoadOrderSpread(itemid);
  242. }
  243. });
  244. Chrome_extension_update("item")
  245. }
  246. // configure the initial table HTML
  247. var buy_order_build_html = '<table class="market_commodity_orders_table"><tr>' + $J(data.buy_order_table).children("tbody").eq(0).children("tr").eq(0).html() + '</tr>';
  248. var sell_order_build_html = '<table class="market_commodity_orders_table"><tr>' + $J(data.buy_order_table).children("tbody").eq(0).children("tr").eq(0).html() + '</tr>';
  249.  
  250. // Make an deep copy object that stores the quantity at each amount
  251. var quantity_buy_order = $J.extend(true, [], data.buy_order_graph);
  252. for (var i = 0; i < quantity_buy_order.length; i++) {
  253. var sum = 0
  254. for (var x = 0; x < i; x++) {
  255. sum += quantity_buy_order[x][1];
  256. }
  257. quantity_buy_order[i][1] -= sum;
  258. }
  259.  
  260. var quantity_sell_order = $J.extend(true, [], data.sell_order_graph);
  261.  
  262. for (var i = 0; i < quantity_sell_order.length; i++) {
  263. var sum = 0
  264. for (var x = 0; x < i; x++) {
  265. sum += quantity_sell_order[x][1];
  266. }
  267. quantity_sell_order[i][1] -= sum;
  268. }
  269.  
  270. // Remove the button if there aren't actually more than 6 buy orders of different value
  271. if (quantity_buy_order.length <= 6) {
  272. $J("#show_more_buy").hide();
  273. }
  274. else if (quantity_buy_order.length > 6) {
  275. $J("#show_more_buy").show();
  276. }
  277.  
  278. if (quantity_sell_order.length <= 6) {
  279. $J("#show_more_sell").hide();
  280. }
  281. else if (quantity_sell_order.length > 6) {
  282. $J("#show_more_sell").show();
  283. }
  284.  
  285.  
  286. for (var i = 0; i < quantity_buy_order.length; i++) {
  287. // append to the buy order html, account for many currencies, languages
  288. buy_order_build_html += '<td align="right">' + data.price_prefix + quantity_buy_order[i][0].toFixed(2) + data.price_suffix + '</td><td align="right">' + quantity_buy_order[i][1] + '</td></tr><tr>';
  289. }
  290. for (var i = 0; i < quantity_sell_order.length; i++) {
  291. // append to the buy order html, account for many currencies, languages
  292. sell_order_build_html += '<td align="right">' + data.price_prefix + quantity_sell_order[i][0].toFixed(2) + data.price_suffix + '</td><td align="right">' + quantity_sell_order[i][1] + '</td></tr><tr>';
  293. }
  294.  
  295. // If there is only one buy order and the total is exact
  296. var total_shown_buy_orders = null;
  297. var total_shown_sell_orders = null;
  298. if (data.buy_order_graph.length > 0) {
  299. total_shown_buy_orders = data.buy_order_graph[data.buy_order_graph.length - 1][1];
  300. }
  301. if (data.sell_order_graph.length > 0) {
  302. total_shown_sell_orders = data.sell_order_graph[data.sell_order_graph.length - 1][1];
  303. }
  304.  
  305. if ((data.buy_order_summary).search(total_shown_buy_orders) == -1 && data.buy_order_graph.length > 0) {
  306. // Not all of the possible listings are shown, put the "or more" tag and calculate the remaining orders
  307. // Get the total amount of buy listings
  308. var totallistings = $J(data.buy_order_summary.replace("Ceny ", "")).text().split(" ")[0];
  309.  
  310. // Update for localization, get the "or more" or "or less" text from the response rather than hard coding in english
  311. var orless = $J(data.buy_order_table).children("tbody").eq(0).children().last().children().eq(0).text().replace(data.price_prefix, "").replace(data.price_suffix, "").replace(/\d+([,.]\d+)?/, "").trim();
  312. buy_order_build_html += '<td align="right">' + data.price_prefix + (quantity_buy_order[quantity_buy_order.length - 1][0] - 0.01).toFixed(2) + data.price_suffix + ' ' + orless + '</td><td align="right">' + (totallistings - total_shown_buy_orders) + '</td></tr><tr>';
  313. }
  314. if ((data.sell_order_summary).search(total_shown_sell_orders) == -1 && data.sell_order_graph.length > 0) {
  315. // Not all of the possible listings are shown, put the "or more" tag and calculate the remaining orders
  316. // Get total amount of buy listings
  317. var totallistings = $J(data.sell_order_summary.replace("Ceny ", "")).text().split(" ")[0];
  318.  
  319. var ormore = $J(data.sell_order_table).children("tbody").eq(0).children().last().children().eq(0).text().replace(data.price_prefix, "").replace(data.price_suffix, "").replace(/\d+([,.]\d+)?/, "").trim();
  320. sell_order_build_html += '<td align="right">' + data.price_prefix + (quantity_sell_order[quantity_sell_order.length - 1][0] + 0.01).toFixed(2) + data.price_suffix + ' ' + ormore + '</td><td align="right">' + (totallistings - total_shown_sell_orders) + '</td></tr><tr>';
  321. }
  322. sell_order_build_html += '</table>', buy_order_build_html += '</table>';
  323. // Overwrite the old table
  324. $J('#market_commodity_forsale').html( data.sell_order_summary );
  325. $J('#market_commodity_buyrequests').html( data.buy_order_summary );
  326. if (data.buy_order_graph.length > 0 && bbo_buy_enable == 1) {
  327. $J('#market_commodity_buyreqeusts_table').html( buy_order_build_html )
  328. }
  329. else {
  330. $J('#market_commodity_buyreqeusts_table').html( data.buy_order_table );
  331. }
  332. if (data.sell_order_graph.length > 0 && bbo_sell_enable == 1) {
  333. $J('#market_commodity_forsale_table').html(sell_order_build_html);
  334. }
  335. else {
  336. $J('#market_commodity_forsale_table').html(data.sell_order_table);
  337. }
  338.  
  339.  
  340. // Create animations
  341. if (show_tables == 1) {
  342. if ($J("#market_commodity_buyreqeusts_table").is(":hidden")) {
  343. $J("#market_commodity_buyreqeusts_table").hide().slideDown();
  344. }
  345. else {
  346. $J("#market_commodity_forsale_table").hide().slideDown();
  347. }
  348. show_tables = 0;
  349. }
  350.  
  351.  
  352. // The rest of this function is just a copy and paste of some of the original code in this function by Valve
  353.  
  354.  
  355.  
  356. // set in the purchase dialog the default price to buy things (which should almost always be the price of the cheapest listed item)
  357. if ( data.lowest_sell_order && data.lowest_sell_order > 0 )
  358. CreateBuyOrderDialog.m_nBestBuyPrice = data.lowest_sell_order;
  359. else if ( data.highest_buy_order && data.highest_buy_order > 0 )
  360. CreateBuyOrderDialog.m_nBestBuyPrice = data.highest_buy_order;
  361.  
  362. // update the jplot graph
  363. // we do this infrequently, since it's really expensive, and makes the page feel sluggish
  364. var $elOrdersHistogram = $J('#orders_histogram');
  365. if ( Market_OrderSpreadPlotLastRefresh
  366. && Market_OrderSpreadPlotLastRefresh + (60*60*1000) < $J.now()
  367. && $elOrdersHistogram.length )
  368. {
  369. $elOrdersHistogram.html('');
  370. Market_OrderSpreadPlot = null;
  371. }
  372.  
  373. if ( Market_OrderSpreadPlot == null && $elOrdersHistogram.length )
  374. {
  375. Market_OrderSpreadPlotLastRefresh = $J.now();
  376.  
  377. $elOrdersHistogram.show();
  378. var line1 = data.sell_order_graph;
  379. var line2 = data.buy_order_graph;
  380. var numYAxisTicks = 11;
  381. var strFormatPrefix = data.price_prefix;
  382. var strFormatSuffix = data.price_suffix;
  383. var lines = [ line1, line2 ];
  384.  
  385. Market_OrderSpreadPlot = $J.jqplot('orders_histogram', lines, {
  386. renderer: $J.jqplot.BarRenderer,
  387. rendererOptions: {fillToZero: true},
  388. title:{text: 'Buy and Sell Orders (cumulative)', textAlign: 'left' },
  389. gridPadding:{left: 45, right:45, top:30},
  390. axesDefaults:{ showTickMarks:false },
  391. axes:{
  392. xaxis:{
  393. tickOptions:{formatString:strFormatPrefix + '%0.2f' + strFormatSuffix, labelPosition:'start', showMark: false},
  394. min: data.graph_min_x,
  395. max: data.graph_max_x
  396. },
  397. yaxis: {
  398. pad: 1,
  399. tickOptions:{formatString:'%d'},
  400. numberTicks: numYAxisTicks,
  401. min: 0,
  402. max: data.graph_max_y
  403. }
  404. },
  405. grid: {
  406. gridLineColor: '#414141',
  407. borderColor: '#414141',
  408. background: '#262626'
  409. },
  410. cursor: {
  411. show: true,
  412. zoom: true,
  413. showTooltip: false
  414. },
  415. highlighter: {
  416. show: true,
  417. lineWidthAdjust: 2.5,
  418. sizeAdjust: 5,
  419. showTooltip: true,
  420. tooltipLocation: 'n',
  421. tooltipOffset: 20,
  422. fadeTooltip: true,
  423. yvalues: 2,
  424. formatString: "<span style=\"display: none\">%s%s</span>%s"
  425. },
  426. series: [{lineWidth:3, fill: true, fillAndStroke:true, fillAlpha: 0.3, markerOptions:{show: false, style:'circle'}}, {lineWidth:3, fill: true, fillAndStroke:true, fillAlpha: 0.3, color:'#6b8fc3', markerOptions:{show: false, style:'circle'}}],
  427. seriesColors: [ "#688F3E" ]
  428. });
  429. }
  430. }
  431.  
  432. } );
  433. }
  434.  
  435. function CreatePriceHistoryGraph( line1, numYAxisTicks, strFormatPrefix, strFormatSuffix )
  436. {
  437. // Valve's native functions don't work properly on items with no listings, little edits were done...
  438. if (document.getElementById("pricehistory") == null) {
  439. $J("#searchResultsTable").append('<div id="pricehistory" class="jqplot-target" style="height: 300px; padding-left: 10px; margin-bottom: 30px;"></div>');
  440. }
  441. var plot = $J.jqplot('pricehistory', [line1], {
  442. title:{text: 'Median Sale Prices', textAlign: 'left' },
  443. gridPadding:{left: 45, right:45, top:25},
  444. axesDefaults:{ showTickMarks:false },
  445. axes:{
  446. xaxis:{
  447. renderer:$J.jqplot.DateAxisRenderer,
  448. tickOptions:{formatString:'%b %#d<span class="priceHistoryTime"> %#I%p<span>'},
  449. pad: 1
  450. },
  451. yaxis: {
  452. pad: 1.1,
  453. tickOptions:{formatString:strFormatPrefix + '%0.2f' + strFormatSuffix, labelPosition:'start', showMark: false},
  454. numberTicks: numYAxisTicks
  455. }
  456. },
  457. grid: {
  458. gridLineColor: '#414141',
  459. borderColor: '#414141',
  460. background: '#262626'
  461. },
  462. cursor: {
  463. show: true,
  464. zoom: true,
  465. showTooltip: false
  466. },
  467. highlighter: {
  468. show: true,
  469. lineWidthAdjust: 2.5,
  470. sizeAdjust: 5,
  471. showTooltip: true,
  472. tooltipLocation: 'n',
  473. tooltipOffset: 20,
  474. fadeTooltip: true,
  475. yvalues: 2,
  476. formatString: '<strong>%s</strong><br>%s<br>%d sold'
  477. },
  478. series:[{lineWidth:3, markerOptions:{show: false, style:'circle'}}],
  479. seriesColors: [ "#688F3E" ]
  480. });
  481.  
  482. plot.defaultNumberTicks = numYAxisTicks;
  483. return plot;
  484.  
  485. }
  486.  
  487.  
  488. function InstallMarketActionMenuButtons()
  489. {
  490. // Valve's native functions don't work properly on items with no listings, little edits were done...
  491. if (document.getElementById("pricehistory") != null) {
  492. for ( var listing in g_rgListingInfo ) {
  493. var asset = g_rgListingInfo[listing].asset;
  494. if (typeof asset != 'undefined') {
  495. if ( typeof g_rgAssets[asset.appid][asset.contextid][asset.id].market_actions != 'undefined' )
  496. {
  497. // add the context menu
  498. var elActionMenuButton = $J('<a></a>');
  499. elActionMenuButton.attr( 'id', 'listing_' + listing + '_actionmenu_button' );
  500. elActionMenuButton.addClass( 'market_actionmenu_button' );
  501. elActionMenuButton.attr( 'href', 'javascript:void(0)' );
  502. $J('#listing_' + listing + '_image').parent().append( elActionMenuButton );
  503.  
  504. $J(elActionMenuButton).click( $J.proxy( function( elButton, rgAsset ) {
  505. HandleMarketActionMenu( elButton.attr( 'id' ), g_rgAssets[rgAsset.appid][rgAsset.contextid][rgAsset.id] );
  506. }, null, elActionMenuButton, asset ) );
  507. }
  508. }
  509. }
  510. }
  511. }
  512.  
  513. function pricehistory_zoomMonthOrLifetime( plotPriceHistory, timePriceHistoryEarliest, timePriceHistoryLatest )
  514. {
  515. // Valve's native functions don't work properly on items with no listings, little edits were done...
  516. if (document.getElementById("pricehistory") != null) {
  517. var timeMonthAgo = new Date( timePriceHistoryLatest.getTime() - ( 30 * 24 * 60 * 60 * 1000 ) );
  518. plotPriceHistory.resetZoom();
  519.  
  520. var days = (timePriceHistoryLatest.getTime() - timePriceHistoryEarliest.getTime()) / ( 24 * 60 * 60 * 1000 );
  521. if ( days / 7 < 1 )
  522. {
  523. var difference = timePriceHistoryLatest.getTime() - timePriceHistoryEarliest.getTime();
  524. plotPriceHistory.axes.xaxis.ticks = [timePriceHistoryEarliest, new Date( timePriceHistoryEarliest.getTime() + difference * 0.25 ), new Date( timePriceHistoryEarliest.getTime() + difference * 0.5 ), new Date( timePriceHistoryEarliest.getTime() + difference * 0.75 ), timePriceHistoryLatest];
  525. }
  526. else
  527. {
  528. plotPriceHistory.axes.xaxis.tickInterval = (days / 7) + " days";
  529. }
  530. if ( timePriceHistoryEarliest > timeMonthAgo )
  531. plotPriceHistory.axes.xaxis.min = timePriceHistoryEarliest;
  532. else
  533. plotPriceHistory.axes.xaxis.min = timeMonthAgo;
  534. plotPriceHistory.axes.xaxis.max = timePriceHistoryLatest;
  535.  
  536. var rgYAxis = GetYAXisForPriceHistoryGraph( plotPriceHistory, plotPriceHistory.axes.xaxis.min, timePriceHistoryLatest );
  537. plotPriceHistory.axes.yaxis.min = rgYAxis[0];
  538. plotPriceHistory.axes.yaxis.max = rgYAxis[1];
  539. plotPriceHistory.axes.yaxis.numberTicks = rgYAxis[2];
  540. plotPriceHistory.axes.yaxis.tickInterval = rgYAxis[4];
  541.  
  542. plotPriceHistory.replot();
  543.  
  544. $J('#pricehistory .jqplot-yaxis').children().first().remove();
  545. $J('#pricehistory .jqplot-yaxis').children().last().remove();
  546.  
  547. return false;
  548. }
  549. }
  550.  
  551. ItemActivityTicker.Load = function() {
  552. // overwrite currency selection
  553. $J.ajax( {
  554. url: 'http://steamcommunity.com/market/itemordersactivity',
  555. type: 'GET',
  556. data: {
  557. country: g_strCountryCode,
  558. language: g_strLanguage,
  559. currency: $J("#currency_buyorder").val() || (typeof( g_rgWalletInfo ) != 'undefined' && g_rgWalletInfo['wallet_currency'] != 0 ? g_rgWalletInfo['wallet_currency'] : 1),
  560. item_nameid: this.m_llItemNameID || itemid,
  561. two_factor: BIsTwoFactorEnabled() ? 1 : 0
  562. }
  563. } ).fail( function( jqxhr ) {
  564. setTimeout( function() { ItemActivityTicker.Load(); }, 10000 );
  565. } ).done( function( data ) {
  566. setTimeout( function() { ItemActivityTicker.Load(); }, 10000 );
  567. if ( data.success == 1 )
  568. {
  569. if ( data.timestamp > ItemActivityTicker.m_nTimeLastLoaded )
  570. {
  571. ItemActivityTicker.m_nTimeLastLoaded = data.timestamp;
  572. ItemActivityTicker.Update( data.activity );
  573. }
  574. }
  575. } );
  576. }
  577. addJS_Node(Chrome_extension_update);
  578. addJS_Node(CreatePriceHistoryGraph);
  579. addJS_Node(pricehistory_zoomMonthOrLifetime);
  580. addJS_Node(InstallMarketActionMenuButtons);
  581. addJS_Node (escapeHtml);
  582. addJS_Node (Market_LoadOrderSpread);
  583. addJS_Node (toggle_state);
  584.  
  585. function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
  586. var D = document;
  587. var scriptNode = D.createElement ('script');
  588. if (runOnLoad) {
  589. scriptNode.addEventListener ("load", runOnLoad, false);
  590. }
  591. scriptNode.type = "text/javascript";
  592. if (text) scriptNode.textContent = text;
  593. if (s_URL) scriptNode.src = s_URL;
  594. if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
  595.  
  596. var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
  597. targ.appendChild (scriptNode);
  598. }
  599. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement