-
-
Save Nonickn/f133d97b6413b61f6574 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
// ==UserScript== | |
// @name Steam Card Buyer | |
// @namespace http://leakforums.org/ | |
// @version 0.1 | |
// @description Easier way to bulk buy cards? | |
// @author You | |
// @include http://steamcommunity.com* | |
// @include https://steamcommunity.com* | |
// @match *://steamcommunity.com/*/gamecards/* | |
// @grant none | |
// @run-at document-end | |
// ==/UserScript== | |
/* | |
idfk | |
*/ | |
var country = 'NO' | |
var currency = 9 | |
var price_url = 'http://steamcommunity.com/market/itemordershistogram?country=' + country + '&language=english¤cy=' + currency + '&item_nameid=' | |
var price_format = '' | |
var cards = {} | |
var current_index = 0; | |
var next_card = null; | |
$J.ajaxSetup({ | |
xhrFields: { | |
withCredentials: true | |
} | |
}); | |
/* | |
if($J('.badge_craft_button').first()[0] !== undefined) { | |
$J.each([0,1,2,3,4], function(i, e) { | |
$J('.badge_craft_button').click() | |
}); | |
} | |
*/ | |
var $found = $J('.badge_card_to_collect_links > a[href^="http://steamcommunity.com/market/listings/753"]') | |
$J('.gamecards_inventorylink').append($J('<div class="buy_cards"><br><span class="found"></span><br><table class="cards"><tr></tr><tr><td align="right"><b>Total:</b></td><td><button class="btn_grey_grey btn_medium" id="plus5" style="padding: 5px;width: 100%">+5</button></td><td class="total"></td></tr><tr></tr><tr><td colspan="3"><button type="button" id="buy_button" class="btn_green_white_innerfade btn_medium_wide" style="padding: 10px 20px;width: 100%">Buy Cards</button></td></table></div>')) | |
function amount_change(item_id, price, e) { | |
quantity = +($J(e).val()) | |
cards[+(item_id)].quantity = quantity | |
$J('#price_'+item_id).text(format_price(price*quantity)) | |
calculate_total() | |
} | |
$J('#buy_button').click(function() { | |
$J(this).hide() | |
buy_card() | |
}) | |
function handleChange(e) { | |
quantity = +($J(this).val()) | |
item_id = +($J(this).attr('item_id')) | |
price = +($J(this).attr('price')) | |
cards[item_id].quantity = quantity | |
$J('#price_'+item_id).text(format_price(price*quantity)) | |
calculate_total() | |
} | |
$J('#plus5').click(function() { | |
$J('.card_amount').val(5).change() | |
}) | |
function update_status(item_id, status) { | |
$J('.status_' + item_id).text(status) | |
} | |
function check_order(co_card) { | |
$J.get('/market/getbuyorderstatus/', {sessionid: g_sessionID, buy_orderid: co_card.orderid}, function(json) { | |
if(co_card.checks == 0) | |
buy_card() | |
console.log(co_card) | |
co_card.checks++; | |
left = co_card.quantity-(+(json.quantity_remaining)) | |
update_status(co_card.item_id, 'Bought '+ left +'/'+ co_card.quantity) | |
if (left == co_card.quantity) { | |
$J('.status_' + co_card.item_id).parent().css('color', '#19D319') | |
return | |
} else { | |
console.log('wait') | |
co_card.checks++; | |
if(co_card.checks >= 50) { | |
update_status(co_card.item_id, 'Waited for too long'); | |
return; | |
} | |
} | |
setTimeout(function() { | |
check_order(co_card); | |
}, 500); | |
}) | |
} | |
function buy_card() { | |
setTimeout(function() { | |
for (card in cards) break; | |
console.log(card) | |
card = cards[card] | |
console.log(card) | |
if(!card) { | |
return | |
} | |
delete cards[card.item_id] | |
if(card.status != 0) { | |
console.log('Tried to buy', card.name, 'twice') | |
return | |
} | |
if(card.quantity == 0) | |
return | |
card.status = 1 | |
update_status(card.item_id, 'Buying Card') | |
$J.post('https://steamcommunity.com/market/createbuyorder/', {sessionid: g_sessionID, currency: currency, appid: 753, market_hash_name: card.hash_name, price_total: card.price*card.quantity, quantity: card.quantity}, function(json) { | |
if(!json.success) { | |
update_status(card.item_id, 'Failed to buy card') | |
console.log(json) | |
return; | |
} | |
card.orderid = json.buy_orderid; | |
update_status(card.item_id, 'Waiting...') | |
check_order(card) | |
}); | |
}, 300); | |
} | |
function calculate_total() { | |
total = 0 | |
$J.each(cards, function(i, e) { | |
total += e.price * e.quantity | |
}) | |
$J('.total').text(format_price(total)) | |
} | |
function format_price(price) { | |
return price_format.replace('{}', ((price) / 100).toFixed(2)) | |
} | |
function append_to_table(item_id) { | |
if(cards[item_id] === undefined) { | |
console.log('Bad build_form item_id =', item_id) | |
return; | |
} | |
card = cards[item_id] | |
$J('.cards').prepend($J('<tr>\ | |
<td align="right">' + card.name + '</td><td>\ | |
<input style="padding: 0;width: 28px;text-align: center;" class="card_amount btn_grey_grey btn_medium" id="amount_'+item_id+'" value="1" min="0" max="5" item_id="'+item_id+'" price="'+card.price+'" />\ | |
<td id="price_'+item_id+'">'+format_price(card.price)+'</td><td class="status_'+item_id+'"></td></tr>')) | |
$J('.card_amount').on('change', handleChange); | |
calculate_total() | |
} | |
function fetch_item_price(item_id) { | |
$J.get(price_url + item_id, function(json) { | |
if(json.success != 1) { | |
console.log('was not a success at fetch_item_price =', item_id) | |
return false | |
} | |
price = +(json.lowest_sell_order) | |
if(price < 5) { | |
console.log('price was lower than 0.005? at fetch_item_price =', item_id, 'price =', price) | |
return false | |
} | |
price += 10 | |
price_format = json.price_prefix + '{}' + json.price_suffix | |
cards[item_id].price = price | |
append_to_table(item_id) | |
}).fail(function() { | |
console.log('error fetch_item_price =', item_id) | |
alert('error') | |
return false | |
}) | |
} | |
function is_already_buying(data) { | |
return data.indexOf('CancelMarketBuyOrder') != -1 | |
} | |
function fetch_item(url) { | |
$J.get(url, function(data) { | |
if(is_already_buying(data)) { | |
console.log('already buying url =', url) | |
return false | |
} | |
item_id = +(data.split('Market_LoadOrderSpread( ').pop().split(' );').shift()) | |
hash_name = data.split('"market_hash_name":"').pop().split('",').shift() | |
name = data.split('market_listing_item_name" style="">').pop().split('</').shift() | |
cards[item_id] = {'url': url, 'price': false, 'name': name,'hash_name': hash_name, 'quantity': 1, 'item_id': item_id, 'status': 0, 'orderid': -1, 'checks': 0, 'bought': 0} | |
$J('.found').text('Fetched: '+Object.keys(cards).length+'/' + $found.length) | |
fetch_item_price(item_id) | |
}).fail(function() { | |
//alert('error on fetch_item url = ' + url) | |
}) | |
} | |
$J('.found').text('Fetched: 0/' + $found.length) | |
$J.each($found, function(i, e) { | |
fetch_item($J(e).attr('href')) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment