-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuyOrders.user.js
111 lines (104 loc) · 3.83 KB
/
BuyOrders.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// ==UserScript==
// @name BuyOrders
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Steam market - show amount of highest buy order for faster selling
// @author steamcommunity.com/id/sudo_q
// @match https://steamcommunity.com/id/*/inventory*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant GM_xmlhttpRequest
// ==/UserScript==
function parseNameid(data) {
//console.log(data.responseText);
self.nameid = data.responseText.match(/Market_LoadOrderSpread\( (\d+)/)[1];
self.itemUrl = "https://steamcommunity.com/market/itemordershistogram?country=US&language=english¤cy=1&item_nameid="+self.nameid+"&two_factor=0";
GM_xmlhttpRequest ({
method: "GET",
url: self.itemUrl,
responseType: "json",
onload: processJSON_Response,
onabort: reportAJAX_Error,
onerror: reportAJAX_Error,
ontimeout: reportAJAX_Error
});
};
function fetchPrice () {
var imainElem = document.getElementById("iteminfo0");
var ialtElem = document.getElementById("iteminfo1");
var linkElem = {};
if (imainElem.style.display == "none")
{
linkElem = document.getElementById("iteminfo1_item_market_actions");
}
else
{
linkElem = document.getElementById("iteminfo0_item_market_actions");
}
var hashUrl = linkElem.children[0].children[0].children[0].href;
if (hashUrl == lastItem)
{
setTimeout(fetchPrice, 500);
}
else
{
lastItem = hashUrl;
//console.log("Fetching " + hashUrl);
GM_xmlhttpRequest ( {
method: "GET",
url: hashUrl,
responseType: "html",
onload: parseNameid,
onabort: reportAJAX_Error,
onerror: reportAJAX_Error,
ontimeout: reportAJAX_Error
} );
}
}
function processJSON_Response (rspObj) {
if (rspObj.status != 200 && rspObj.status != 304) {
reportAJAX_Error (rspObj);
return;
}
//-- The payload from the API will be in rspObj.response.
var pyLd = rspObj.response;
var highestBuyOrder = pyLd.highest_buy_order;
var mainElem = document.getElementById("iteminfo0");
var altElem = document.getElementById("iteminfo1");
var modElem = {};
if (mainElem.style.display == "none")
{
modElem = document.getElementById("iteminfo1_item_market_actions");
}
else
{
modElem = document.getElementById("iteminfo0_item_market_actions");
}
highestBuyOrder = highestBuyOrder / 100;
highestBuyOrder = highestBuyOrder.toLocaleString("en-US", {style:"currency", currency:"USD"});
var brElem = document.createElement("br");
modElem.children[0].children[1].append("Sell for: "+highestBuyOrder);
modElem.children[0].children[1].appendChild(brElem);
disableObserver = false;
//console.log("Enabled observer");
}
function reportAJAX_Error (rspObj) {
console.error (`TM scrpt => Error ${rspObj.status}! ${rspObj.statusText}`);
}
var itemUrl = "";
var lastItem = "";
var targetNode = document.getElementsByClassName("item_market_actions")[0];
var targetNodeAlt = document.getElementsByClassName("item_market_actions")[1];
var config = { characterData: true, childList: true }; // Options for the observer (which mutations to observe)
// Create an observer instance linked to the callback function
var disableObserver = false;
var observer = new MutationObserver(function(mutationsList) {
if (!disableObserver)
{
disableObserver = true;
//console.log("Disabled observer");
fetchPrice();
}
});
// Start observing the target node for configured mutations
observer.observe(targetNodeAlt, config);
observer.observe(targetNode, config);