Skip to content

Instantly share code, notes, and snippets.

@overwatcheddude
Last active June 2, 2024 13:44
Show Gist options
  • Save overwatcheddude/616f93ff04d5e62a80ad58b59d2c3698 to your computer and use it in GitHub Desktop.
Save overwatcheddude/616f93ff04d5e62a80ad58b59d2c3698 to your computer and use it in GitHub Desktop.
This JavaScript code allows you to download Steam purchase history table as a CSV file.
function downloadTableAsCSV(tableClass, filename) {
// Get the table element using class name
var table = document.getElementsByClassName(tableClass)[0];
// Get all rows of the table
var rows = table.getElementsByTagName("tr");
// Create the CSV string
var csvContent = "";
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var cells = row.getElementsByTagName("td");
// Add each cell data with comma separator
for (var j = 0; j < cells.length; j++) {
var cell = cells[j];
var cellText = cell.innerText.replace(/"/g, '""').replace(/[\n\r,]/g, ''); // Escape double quotes, remove commas and line breaks for CSV
csvContent += cellText + (j < cells.length - 1 ? "," : "\n");
}
}
// Create a downloadable blob object
var blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8' });
// Create a downloadable link
var link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = filename || 'table.csv';
// Simulate a click to trigger download
link.click();
}
// Usage
var tableClass = "wallet_history_table";
var filename = "wallet_history.csv";
downloadTableAsCSV(tableClass, filename);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment