Created
July 31, 2024 04:55
-
-
Save HKayn/e0ad3370e053d3ed32c737ed06498d89 to your computer and use it in GitHub Desktop.
A small script to find out how much money you've spent on Bandcamp. To be executed inside your browser's devTools.
This file contains hidden or 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
| /* | |
| How to use this script: | |
| 1. Navigate to your Purchases page on Bandcamp. | |
| 2. Open the browser devTools and open the "Network" tab, | |
| then activate the filter that says something like "Fetch/XHR". | |
| 3. Click the "view all x purchases" button on the bottom of the page. | |
| In the network tab, there should be a new entry with the name "get_items". | |
| 4. Click on that entry. In the new panel that opens, select the "Payload" tab. | |
| 5. Copy the values there into the 3 variables below, like this: | |
| const username = "hkayn"; | |
| (Don't worry about the last_token value.) | |
| 6. Adjust the "emergencyBreak" variable to be slightly higher than the amount of your purchases divided by 10. | |
| 7. Open the "Console" tab in your devTools. Paste this script into the console and press Enter. | |
| Executing this script may take a long while depending on how many purchases you've made. | |
| Eventually you'll see an Array output in the console that you can open to see how much you've spent in each currency. | |
| */ | |
| const username = ""; | |
| const platform = ""; | |
| const crumb = ""; | |
| const emergencyBreak = 60; | |
| function getPostBody(lastToken = undefined) { | |
| let obj = {}; | |
| obj.username = username; | |
| if (lastToken !== undefined) obj.last_token = lastToken; | |
| obj.platform = platform; | |
| obj.crumb = crumb; | |
| return obj; | |
| } | |
| let lastToken = undefined; | |
| let response; | |
| const currencyTotalsMap = new Map(); | |
| let emergencyBreakCounter = 0; | |
| while (emergencyBreakCounter < emergencyBreak) { | |
| emergencyBreakCounter++; | |
| response = await fetch("/api/orderhistory/1/get_items", { | |
| method: "POST", | |
| body: JSON.stringify(getPostBody(lastToken)), | |
| }) | |
| responseJson = await response.json(); | |
| if (responseJson.items.length === 0) break; | |
| lastToken = responseJson.last_token; | |
| responseJson.items.forEach(item => { | |
| let itemTotal = item.base_price + item.additional_contribution + item.tax; | |
| let itemCurrency = item.currency; | |
| console.log(`Processing ${item.item_title} by ${item.artist_name} (${itemCurrency} ${itemTotal})`); | |
| currencyTotalsMap.set( | |
| itemCurrency, | |
| (currencyTotalsMap.get(itemCurrency) ?? 0) + itemTotal | |
| ); | |
| }) | |
| } | |
| Array.from(currencyTotalsMap.entries()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment