Created
March 25, 2014 09:02
-
-
Save eknowles/9757719 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".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