Created
December 11, 2019 23:27
-
-
Save MRuy/0598e989df727a33859f8c777934f2dc to your computer and use it in GitHub Desktop.
Load all inventory history data
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
// Copy and paste into console on the following URL: | |
// https://steamcommunity.com/my/inventoryhistory/?app%5B%5D=730 | |
(async _ => { | |
const loadMoreBtnSelector = '#load_more_button:not([style*="display:none"])'; | |
let pagesLoaded = 0; | |
console.time('loadall'); | |
console.log(g_historyCursor); | |
while (g_historyCursor !== null) { | |
pagesLoaded++; | |
await waitForSelector(loadMoreBtnSelector); | |
await sleep(100); | |
document.querySelector(loadMoreBtnSelector).click(); | |
await sleep(1000); | |
} | |
console.log(g_historyCursor); | |
console.timeEnd('loadall'); | |
console.log('Pages loaded', pagesLoaded); | |
function sleep(ms) { | |
return new Promise(r => setTimeout(r, ms)); | |
} | |
function waitForSelector(selector) { | |
return new Promise((resolve, reject) => { | |
let el = document.querySelector(selector); | |
if (el) {resolve(el);} | |
new MutationObserver((mutationRecords, observer) => { | |
Array.from(document.querySelectorAll(selector)).forEach((element) => { | |
resolve(element); | |
observer.disconnect(); | |
}); | |
}) | |
.observe(document.documentElement, { | |
childList: true, | |
subtree: true | |
}); | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment