|
(async () => { |
|
// Find all buttons on the page that have the claim value, e.g., the |
|
// button you'd normally click to claim the download. |
|
const buttons = Array.from(document.getElementsByTagName('button')) |
|
.filter(btn => btn.value === 'claim'); |
|
|
|
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); |
|
|
|
const claim = async (btn) => { |
|
// jQuery is still useful! |
|
const form = $(btn.parentElement).serialize() |
|
+ '&action=claim'; |
|
|
|
// Send an HTTP POST message to the current URL in the browser. |
|
await fetch(window.location, { |
|
method: 'POST', |
|
credentials: 'include', |
|
headers: { |
|
// Mimic all of the headers that are sent normally when you click. |
|
['Accept']: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8', |
|
['Accept-Language']: 'en-US,en;q=0.5', |
|
['Accept-Encoding']: 'gzip, deflate, br', |
|
['Content-Type']: 'application/x-www-form-urlencoded', |
|
['Upgrade-Insecure-Requests']: '1', |
|
['Sec-Fetch-Dest']: 'document', |
|
['Sec-Fetch-Mode']: 'navigate', |
|
['Sec-Fetch-Site']: 'same-origin', |
|
['Sec-Fetch-User']: '?1', |
|
}, |
|
body: form, |
|
redirect: 'manual' |
|
}); |
|
}; |
|
|
|
// Claim each of the downloads |
|
for (const button of buttons) { |
|
await claim(button); |
|
// Be kind to the itch.io servers |
|
await sleep(2000); |
|
} |
|
console.log('finished', { count: buttons.length }); |
|
})(); |