-
Notifications
You must be signed in to change notification settings - Fork 0
/
dota2lounge.js
45 lines (42 loc) · 1.55 KB
/
dota2lounge.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
/*! Lounge prices | (c) 2015 Solant */
function getPricesWithCurrency(){
chrome.storage.sync.get({
currency: 1,
status: true
}, function(items) {
getPrices(items.currency);
});
//Instead of dom mutation event, kind of dirty hack
setTimeout(getPricesWithCurrency, 1000);
}
getPricesWithCurrency();
function getPrices(currencyId){
$(".item").not(":has(.value)").each(function(index){
var itemName = $(this).children("img").attr("alt");
var itemRarity = $(this).children(".rarity").html();
if(itemName.startsWith("Any") || itemRarity == "Gift" || itemRarity == "Card" || itemName == "+ More"
|| itemRarity == "DLC" || itemRarity == "Background" || itemRarity == "Icon" || itemName == "Not Tradable" || itemName == "Real Money" || itemName == "Offers")
return;
$(this).prepend("<div class='value'>Loading</div>");
var itemPrice;
var itemUrl = "https://steamcommunity.com/market/priceoverview/?currency="+currencyId+"&appid=570&market_hash_name="+encodeURIComponent(itemName);
var xhr = new XMLHttpRequest();
xhr.open("GET", itemUrl, true);
xhr.onreadystatechange = (function(selector) {
return function() {
if (xhr.readyState == 4) {
var json = JSON.parse(xhr.responseText);
if(json['success']){
if(json['lowest_price'] !== undefined)
$(selector).children(".value").html(json['lowest_price'].replace(/[\.,]--/g, ""));
else
$(selector).children(".value").html("???");
} else {
$(selector).children(".value").html("???");
}
}
}
})(this)
xhr.send();
});
}