FAST SELL STEAM

Fast sell Steam items with the current price

当前为 2024-05-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name FAST SELL STEAM
  3. // @include http*://steamcommunity.com/profiles/*/inventory*
  4. // @include http*://steamcommunity.com/id/*/inventory*
  5. // @description Fast sell Steam items with the current price
  6. // @version 1.0
  7. // @namespace https://greasyfork.org/users/6507
  8. // ==/UserScript==
  9. //
  10. //
  11. //
  12. function insertAfter(referenceNode, newNode) {
  13. referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
  14. }
  15.  
  16. async function asyncQuerySelector(selector, win = window) {
  17. return new Promise(resolve => {
  18. const interval = setInterval(() => {
  19. const node = win.document.querySelector(selector);
  20. if (node) {
  21. clearInterval(interval);
  22. resolve(node);
  23. }
  24. }, 250);
  25. });
  26. }
  27.  
  28. /**
  29. * Disable auto-reload Steam inventory on sell as it is resetting all filters
  30. */
  31. CInventory.prototype.GetCountTotalItems = function () {
  32. return 1001;
  33. };
  34.  
  35. document.addEventListener('click', () => {
  36. const sellButtons = document.querySelectorAll('.item_market_action_button:not(:has(+ .fast_sell)):not(.fast_sell)');
  37. sellButtons.forEach((btn) => {
  38. const fastSellButton = btn.cloneNode(true);
  39. fastSellButton.classList.add('fast_sell', 'btn_darkblue_white_innerfade');
  40. fastSellButton.classList.remove('item_market_action_button_green');
  41. fastSellButton.style.marginLeft = '10px';
  42. fastSellButton.querySelector('.item_market_action_button_contents').innerText = 'Fast Sell';
  43. fastSellButton.href = '';
  44. fastSellButton.addEventListener('click', (event) => {
  45. event.preventDefault();
  46. fastSellCurrentItem(btn);
  47. });
  48. insertAfter(btn, fastSellButton);
  49. });
  50. });
  51.  
  52. function getCurrentItemPrice() {
  53. const pricesDivs = [...document.querySelectorAll('.inventory_iteminfo')].filter((x) => x.style.display !== 'none');
  54. if (pricesDivs.length > 1 || !pricesDivs.length) {
  55. return null;
  56. }
  57.  
  58. const [priceDiv] = pricesDivs;
  59. const priceText = priceDiv.querySelector('.item_market_actions').innerText;
  60. const PRICE_REGEX = /(\d+(?:\.|,?)\d+)/;
  61. const [, price] = priceText.match(PRICE_REGEX) || [];
  62. return price;
  63. }
  64.  
  65. async function fastSellCurrentItem(sellButton) {
  66. const price = getCurrentItemPrice();
  67. if (!price) {
  68. return alert("Can't determine price");
  69. }
  70.  
  71. sellButton.click();
  72. const priceInput = await asyncQuerySelector('#market_sell_buyercurrency_input');
  73. priceInput.value = price;
  74. priceInput.dispatchEvent(new KeyboardEvent('keyup'));
  75. document.querySelector('#market_sell_dialog_accept_ssa').checked = true;
  76. document.querySelector('#market_sell_dialog_accept').click();
  77. document.querySelector('#market_sell_dialog_ok').click();
  78. }
  79.