BackpackDecalSpotter/script.js

135 lines
5.1 KiB
JavaScript
Raw Normal View History

2024-03-07 19:58:24 +02:00
var checkable_accounts = {
'76561198311319887': 'Weapon Crusher', '76561199039790818': 'Megumin [⇄ 24/7]', '76561199140988104': 'Bela🔥⇄',
'76561198104201017': 'Daniela⚡⇄', '76561199125108615': 'Squid Girl Bot', '76561199550718094': '¹⚡️ refbot.tf',
'76561199202848205': 'The Agency', '76561199034865605': '[⇄] Amazon Prime ⚡24/7⚡'
};
var ignorable_accounts = ['76561198042562877', '76561199193118161', '76561199090583973'];
var ignored_accounts = [];
2024-03-07 16:13:33 +02:00
decaled_objects = { 'Conscientious Objector': '3.66', 'Clan Pride': '2.11', 'Flair!': '4.22', 'Photo Badge': '2.44' }
2024-03-07 19:58:24 +02:00
backpack_page_limit = 10;
2024-03-07 16:13:33 +02:00
function fetchAccounts() {
for (const [item, price] of Object.entries(decaled_objects)) {
handleItem(item, price);
}
}
function handleItem(item, price) {
2024-03-07 19:58:24 +02:00
var stop = false;
2024-03-07 16:13:33 +02:00
for (let i = 1; i <= backpack_page_limit; i++) {
2024-03-07 19:58:24 +02:00
var url = 'https://backpack.tf/classifieds';
var data = 'page=' + i + '&item=' + encodeURIComponent(item) + '&quality=6&tradable=1&craftable=1&australium=-1&killstreak_tier=0&numeric=price&comparison=lt&value=' + price + '&low=' + price;
2024-03-07 16:13:33 +02:00
$.ajax({
dataType: 'html',
2024-03-07 19:58:24 +02:00
url: url,
data: data,
2024-03-07 16:13:33 +02:00
tryCount: 0,
2024-03-07 19:58:24 +02:00
retryLimit: 20,
2024-03-07 16:13:33 +02:00
success: function (msg) {
if ($('.col-md-6:first .alert', msg).length > 0) {
2024-03-07 19:58:24 +02:00
stop = true;
2024-03-07 16:13:33 +02:00
return false;
}
$('.col-md-6:first .user-link', msg).each(function () {
2024-03-07 19:58:24 +02:00
var steam_id = $(this).attr('data-id');
var steam_name = $(this).attr('data-name');
if (ignorable_accounts.includes(steam_id)) {
if (!ignored_accounts.includes(steam_id)) {
var ignore_accounts = $('#ignore-accounts');
ignore_accounts.append('<a href="https://next.backpack.tf/profiles/' + steam_id + '">' + steam_name + '</a>; ');
ignore_accounts.fadeIn();
ignored_accounts.push(steam_id);
}
} else if (!(steam_id in checkable_accounts)) {
handleAccount(steam_id, steam_name);
checkable_accounts[steam_id] = steam_name;
}
2024-03-07 16:13:33 +02:00
});
},
error: function (response, status, error) {
if (response.status == 429) {
this.tryCount++;
if (this.tryCount <= this.retryLimit) {
setTimeout(() => {
$.ajax(this);
2024-03-07 19:58:24 +02:00
}, 3000 + i * 300 + this.retryCount * 70 + Math.floor(Math.random() * 1000));
2024-03-07 16:13:33 +02:00
return;
}
}
}
});
2024-03-07 19:58:24 +02:00
if (stop) {
break;
}
2024-03-07 16:13:33 +02:00
}
}
function handleAccounts() {
2024-03-07 19:58:24 +02:00
for (const [steam_id, steam_name] of Object.entries(checkable_accounts)) {
handleAccount(steam_id, steam_name);
2024-03-07 16:13:33 +02:00
}
}
2024-03-07 19:58:24 +02:00
function handleAccount(steam_id, steam_name) {
var url = "https://backpack.tf/_inventory/" + steam_id;
2024-03-07 16:13:33 +02:00
$.ajax({
dataType: 'json',
url: url,
tryCount: 0,
2024-03-07 19:58:24 +02:00
retryLimit: 30,
success: function (msg) { handleHTML(steam_id, steam_name, msg['html']); },
2024-03-07 16:13:33 +02:00
error: function (response, status, error) {
2024-03-07 19:58:24 +02:00
this.tryCount++;
if (this.tryCount <= this.retryLimit) {
setTimeout(() => {
$.ajax(this);
}, 3000 + this.tryCount * 40 + Math.floor(Math.random() * 1000));
return;
2024-03-07 16:13:33 +02:00
}
}
});
}
2024-03-07 19:58:24 +02:00
function handleHTML(steam_id, steam_name, html_string) {
2024-03-07 16:13:33 +02:00
html = $.parseHTML(html_string);
var decaled_items = $('div.decal', html);
if (decaled_items.length == 0) {
var empty_accounts = $('#empty-accounts');
2024-03-07 19:58:24 +02:00
empty_accounts.append('<a href="https://next.backpack.tf/profiles/' + steam_id + '">' + steam_name + '</a>; ');
2024-03-07 16:13:33 +02:00
empty_accounts.fadeIn();
return false;
}
var inventory = $('<div class="inventory"></div>');
2024-03-07 19:58:24 +02:00
inventory.append('<a href="https://next.backpack.tf/profiles/' + steam_id + '"><h3>' + steam_name + '</h3></a>');
2024-03-07 16:13:33 +02:00
decaled_items.each(function () {
var url = "https://next.backpack.tf/item/" + $(this).parent().attr('data-id');
var a = $('<a href="' + url + '"></a>');
a.append($(this).parent());
inventory.append(a);
});
var inventories = $('.inventory');
if (inventories.length > 0) {
var child_count = inventory.children().length;
inventory.attr('data-items', child_count);
var last_div = null;
inventories.each(function () {
if (child_count > $(this).children().length) {
return false;
}
last_div = $(this);
});
if (last_div) {
last_div.after(inventory);
} else {
$('body').prepend(inventory);
}
} else {
$('#empty-accounts').before(inventory);
}
}
$(document).ready(function () {
2024-03-07 19:58:24 +02:00
handleAccounts();
fetchAccounts();
2024-03-07 16:13:33 +02:00
});