Skip to content

Instantly share code, notes, and snippets.

@Pandiora
Forked from jabczyk/knick-knack-bot.js
Last active January 16, 2019 18:00
Show Gist options
  • Save Pandiora/69b8e0932923bde56356fcd686aa6e8c to your computer and use it in GitHub Desktop.
Save Pandiora/69b8e0932923bde56356fcd686aa6e8c to your computer and use it in GitHub Desktop.
Consume all knick knacks in your inventory - Really! Or maybe?
/*
Removed useless info about the author - advertise yourself if you actually know what you're doing - THX!
Probably not one single bit is left from the original source, since Mister Advertiser actually ignored
all the different item-types. Kerikek (sleep is my copy-pasta of another copy-pasta ...∞)
So how to use this crap?
1. you don't need to load your inventory, but it would be a good idea to reload the site one time before you start
(your inventory site -> https://steamcommunity.com/my/inventory/)
2. open your developer-tools and go to console (maybe press F12)
3. paste this script to your console and execute it by hitting enter if you want to consume all your knick knacks
4. the script will log the progress to your console, no fancy dialog-box sorry ain't got no more 2 mins
5. the script will reload the site after it finished
6. you should leave the tab with the script running, open, or use a separate window to run it (NOT TAB!)
BONUS:
change kk.consumeAmount(); to await kk.checkAmount(); | to get the total of knick knacks you got in your inventory
change kk.consumeAmount(); to kk.consumeAmount(x); | x = number of knick knacks you want to consume
change kk.consumeAmount(); to kk.consumeAmount(x,y); | x = look above, y = delay between requests
*/
const kk = (() => {
const checkTags = (a,s,p)=> {let r=0;a.map(t=>{if(t[p]===s)r=1});return r};
const parseAction = (str) => {return JSON.stringify(JSON.parse(/,\s([\S\s.]*),\s1/gm.exec(str)[1]))};
const parseItype = (str) => {return /,\s(\d+),/gm.exec(str)[1]};
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const checkAmount = async()=> {const c=await getData();return c.length};
const getData = async()=> {
// um, we could wait for inventory to load with just one line of code?!
await g_ActiveInventory.LoadCompleteInventory();
const inventory = window.g_ActiveInventory.m_rgPages,
nodes = inventory.map(page => { return Array.from(page[0].childNodes) }),
childs = nodes
.flat(1)
.reduce((r, child) => {
if(child.rgItem
&& child.rgItem.contextid == 6
&& child.rgItem.appid == 753
&& checkTags(child.rgItem.description.tags,"item_class_6","internal_name")
){
const data = child.rgItem.description.owner_actions[0].link;
r.push({
appid: child.rgItem.description.market_fee_app,
assetid: child.rgItem.assetid,
item_type: parseItype(data),
action_params: parseAction(data)
});
}
return r;
}, []);
return childs;
};
const consumeAmount = async(cnt, ms) => {
ms = ms || 500;
let kk = await getData(), index = 0;
if(cnt && cnt <= kk.length) kk.length = cnt;
const url = `${g_strProfileURL}/ajaxactivateconsumable/`,
sessionid = g_sessionID;
for(let item of kk){
index++;
const params = {
sessionid: sessionid,
appid: item.appid,
item_type: item.item_type,
assetid: item.assetid,
actionparams: item.action_params
};
try {
const success = await $J.post(url,params);
await sleep(ms);
if(!success || !success.bActivated) console.log(`Failed to consume KnickKnack No. ${index}`);
console.log(`KnickKnack consumed (${index}/${kk.length})`);
} catch(e){
console.log(`Failed to consume KnickKnack No. ${index}`);
continue;
};
}
console.log('Done consuming KnickKnacks!');
setTimeout(document.location.reload(),10000);
};
return {
checkAmount,
consumeAmount
};
})();
kk.consumeAmount();
@ITpaolo
Copy link

ITpaolo commented Jan 16, 2019

Works much better than the original one. Thanks mate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment