Skip to content

Instantly share code, notes, and snippets.

@eknowles
Created March 25, 2014 09:02
Show Gist options
  • Save eknowles/9757719 to your computer and use it in GitHub Desktop.
Save eknowles/9757719 to your computer and use it in GitHub Desktop.
$(".item").hover(
function () {
var SearchItem = $(this);
// on mouse in
if (SearchItem.hasClass('priced')) {
// has already set a price so dont do anything
} else {
SearchItem.find('.rarity').html('Loading...');
var itemurl = "http://steamcommunity.com/market/listings/" + gameid + "/" + SearchItem.find('img.smallimg').attr("alt") + "/";
var xhr = new XMLHttpRequest();
xhr.open("GET", itemurl, true);
xhr.withCredentials = true;
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
var item_price = xhr.responseText.match(/<span class="market_listing_price market_listing_price_with_fee">\r\n(.+)<\/span>/g);
if (item_price) {
$(item_price).each(function (index, value) {
if (!(value.match(/\!/))) {
item_to_get = value.match(/<span class="market_listing_price market_listing_price_with_fee">\r\n(.+)<\/span>/);
return false;
}
});
lowest_price = item_to_get[1].trim();
SearchItem.find('.rarity').html(lowest_price);
SearchItem.addClass('priced');
} else {
SearchItem.find('.rarity').html('Not Found');
}
}
};
xhr.send();
}
}, function () {
// on mouse out
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment