-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSteam_-_Set_sale_price_for_inventory.user.js
86 lines (72 loc) · 2.77 KB
/
Steam_-_Set_sale_price_for_inventory.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// ==UserScript==
// @name Steam - Set sale price for inventory
// @author Tailszefox
// @namespace localhost
// @description Automatically sets sale price for inventory items
// @icon https://i.imgur.com/5jMQgzt.png
// @include https://steamcommunity.com/id/tailszefox/inventory
// @include https://steamcommunity.com/id/tailszefox/inventory/
// @include https://steamcommunity.com/id/tailszefox/inventory/#*
// @version 1.0
// @grant none
// ==/UserScript==
// Sets the buyer price to the desired value
function setBuyerPrice(price)
{
document.querySelector("#market_sell_buyercurrency_input").value = price;
SellItemDialog.OnBuyerPriceInputKeyUp();
}
// What to do when the Sell Item dialog appears
function process()
{
// Get the current price
var divPrice = jQuery(".item_market_action_button_contents:visible")[0].parentNode.parentNode.querySelectorAll("div")[2];
var textPrice = jQuery(divPrice).text();
var price = priceRegex.exec(textPrice)[1];
// Set it in the seller price box
setBuyerPrice(price);
// Check the box about agreeing to stuff
document.querySelector("#market_sell_dialog_accept_ssa").checked = true;
// Get the last few prices the item was sold at
var lastPrices = SellItemDialog.m_plotPriceHistory._plotData[0].slice(-3);
var lastPricesText = "Last prices from most recent: ";
// Remove the price list if we had already added it
jQuery("#divPrices").remove();
// Add a div to contain the price history
var divPrices = document.createElement("div");
divPrices.id = "divPrices";
divPrices.style.float = "left";
jQuery(".zoom_controls:visible").before(divPrices);
divPrices.appendChild(document.createTextNode(lastPricesText));
// Add links to change the price
for (var i = lastPrices.length - 1; i >= 0; i--)
{
var p = lastPrices[i][1]
var a = document.createElement("a");
a.appendChild(document.createTextNode(p.toFixed(2)));
a.addEventListener("click", function(e)
{
var price = e.target.text + "€";
setBuyerPrice(price);
}, false);
divPrices.appendChild(a);
divPrices.appendChild(document.createTextNode("€ "));
};
}
var priceRegex = /(\d+,\d+€)/;
// Wait for the price history to be displayed before doing anything
var observer = new MutationObserver(function(m)
{
for (var i = m.length - 1; i >= 0; i--)
{
var mutation = m[i]
// If it's been set to be visible
if(mutation.target.style.visible != "none")
{
process();
}
};
});
// Attach our observer to the price history element
var priceHistory = document.querySelector("#pricehistory");
observer.observe(priceHistory, { attributes: true });