Skip to content

Instantly share code, notes, and snippets.

@burdiuz
Last active February 19, 2020 21:24
Show Gist options
  • Save burdiuz/8ecc0c3c53e4dcdc26a5afca1c485a67 to your computer and use it in GitHub Desktop.
Save burdiuz/8ecc0c3c53e4dcdc26a5afca1c485a67 to your computer and use it in GitHub Desktop.
Steam market script that filters out items with locked properties
(() => {
let index = 0;
const step = 10;
const root = document.querySelector('#searchResultsRows');
root.innerHTML = '';
const loadPage = (page, count) => {
fetch(`https://steamcommunity.com/market/listings/<GAME_ID>/<ITEM_NAME>/render/?query=&start=${page*count}&count=${count}&country=RU&language=english&currency=5`)
.then((response) => response.json())
.then(({results_html, listinginfo, assets}) => {
assets = assets['570']['2'];
for(let p in listinginfo) {
listinginfo[p].asset = assets[listinginfo[p].asset.id];
}
root.innerHTML += `<div style="color: rgb(153, 204, 255);">${page+1}</div> ${results_html}`;
const section = root.querySelector(`.market_listing_table_header:nth-child(${(page+1)*2})`);
filterItems(section, listinginfo);
loadNextPage();
})
.catch(() => setTimeout(() => loadPage(page, count), 5000));
}
const loadNextPage = () => {
setTimeout(() => loadPage(++index, step), 500);
}
const filterItems = (section, listinginfo) => {
let item = section;
let nextItem;
while((nextItem = item.nextElementSibling)) {
const id = nextItem.className.match(/listing_(\d+)/)[1];
const descriptions = listinginfo[id].asset.descriptions;
if(descriptions.find(({value}) => (value.indexOf('(Locked)')>=0))) {
nextItem.parentElement.removeChild(nextItem);
} else {
item = nextItem;
}
}
};
loadPage(index, step);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment