BackpackDecalSpotter/script.js

179 lines
6.9 KiB
JavaScript
Raw Normal View History

2024-03-07 19:58:24 +02:00
var checkable_accounts = {
2024-03-31 18:53:59 +03:00
'76561198311319887': 'Weapon Crusher'
2024-03-07 19:58:24 +02:00
};
2024-03-24 09:04:27 +02:00
var ignorable_accounts = ['76561198042562877', '76561199193118161', '76561199090583973', '76561198103306049',
'76561198093294992', '76561198109434661', '76561198080691777', '76561199209645193', '76561198176218038',
2024-04-11 07:47:09 +03:00
'76561198257334931', '76561198931095630', '76561198131872819', '76561198992992515', '76561199212467171',
2024-05-09 10:07:20 +03:00
'76561198077063170', '76561198425401222', '76561198894975185', '76561198838991191', '76561198340433719',
2024-08-30 14:07:43 +03:00
'76561198013043575', '76561199065090344', '76561198268232003', '76561199048217964', '76561199530159630',
2024-11-09 18:57:35 +02:00
'76561198127485269', '76561198342313822', '76561198312709731', '76561199233501388', '76561198284551661',
2024-12-02 18:17:03 +02:00
'76561198272789816', '76561199480386464', '76561199571032477', '76561198837917799', '76561198983391628',
2024-12-08 11:59:41 +02:00
'76561198403393033', '76561199182466000'];
2024-03-07 19:58:24 +02:00
var ignored_accounts = [];
2024-11-21 17:27:51 +02:00
decaled_objects = { 'Conscientious Objector': '4.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-11-21 17:27:51 +02:00
retryLimit: 10,
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)) {
2024-03-21 14:50:16 +02:00
var ignore_accounts = $('#ignored-accounts');
2024-03-21 21:06:09 +02:00
ignore_accounts.append(getHiddenAccountLink(steam_id, steam_name) + '; ');
2024-03-07 19:58:24 +02:00
ignore_accounts.fadeIn();
ignored_accounts.push(steam_id);
}
2024-03-21 21:06:09 +02:00
2024-03-07 19:58:24 +02:00
} 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-21 14:50:16 +02:00
function getHiddenAccountLink(steam_id, steam_name) {
2024-03-21 21:06:09 +02:00
return '<a href="https://next.backpack.tf/profiles/' + steam_id + '">' + steam_name + '</a>';
}
function previewFilteredItem() {
$('li', $(this)).fadeIn(100)
}
function hideFilteredItem() {
$('li', $(this)).fadeOut(100)
2024-03-21 14:50:16 +02:00
}
2024-03-07 19:58:24 +02:00
function handleHTML(steam_id, steam_name, html_string) {
2024-03-21 14:50:16 +02:00
var html = $.parseHTML(html_string);
var filtered_item_count = 0;
2024-03-21 21:06:09 +02:00
var filtered_item_previews = [];
2024-03-07 16:13:33 +02:00
var decaled_items = $('div.decal', html);
if (decaled_items.length == 0) {
var empty_accounts = $('#empty-accounts');
2024-03-21 21:06:09 +02:00
empty_accounts.append(getHiddenAccountLink(steam_id, steam_name) + '; ');
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 () {
2024-03-21 14:50:16 +02:00
var parent = $(this).parent();
2024-03-21 16:14:21 +02:00
var is_strange = parent.hasClass('q-440-11');
var is_uncraftable = parent.hasClass('nocraft');
2024-03-31 18:53:59 +03:00
var is_untradable = parent.hasClass('notrade');
2024-03-21 16:14:21 +02:00
var is_price_in_keys = $('.bottom-right span', parent).text().includes('key');
2024-03-21 21:06:09 +02:00
var url = "https://next.backpack.tf/item/" + parent.attr('data-id');
var a = $('<a href="' + url + '"></a>');
a.append(parent);
2024-03-31 18:53:59 +03:00
if (is_strange || is_uncraftable || is_untradable || is_price_in_keys) {
2024-03-21 14:50:16 +02:00
filtered_item_count++;
2024-03-21 21:06:09 +02:00
parent.addClass('filtered-item');
a.on("mouseenter", previewFilteredItem).on("mouseleave", hideFilteredItem)
a.append(filtered_item_count);
var separator = '';
if (filtered_item_previews.length) {
separator = ', ';
}
filtered_item_previews.push(separator, a)
2024-03-21 14:50:16 +02:00
return;
}
2024-03-07 16:13:33 +02:00
inventory.append(a);
});
2024-03-21 14:50:16 +02:00
if (filtered_item_count) {
2024-03-21 21:06:09 +02:00
var link = getHiddenAccountLink(steam_id, steam_name);
$('#filtered-accounts').append(link, ' (', filtered_item_previews, '); ');
2024-03-21 14:50:16 +02:00
$('#filtered-accounts').fadeIn();
}
var item_count = inventory.children().length - 1;
if (item_count <= 0) {
return false;
}
2024-03-07 16:13:33 +02:00
var inventories = $('.inventory');
if (inventories.length > 0) {
2024-03-21 14:50:16 +02:00
inventory.attr('data-items', item_count);
2024-03-07 16:13:33 +02:00
var last_div = null;
inventories.each(function () {
2024-03-22 14:25:48 +02:00
if (item_count > $(this).children().length) {
2024-03-07 16:13:33 +02:00
return false;
}
last_div = $(this);
});
if (last_div) {
last_div.after(inventory);
} else {
$('body').prepend(inventory);
}
} else {
2024-03-21 14:50:16 +02:00
$('#filtered-accounts').before(inventory);
2024-03-07 16:13:33 +02:00
}
}
$(document).ready(function () {
2024-03-07 19:58:24 +02:00
handleAccounts();
2024-03-21 21:06:27 +02:00
fetchAccounts();
2024-03-07 16:13:33 +02:00
});