Skip to content

Instantly share code, notes, and snippets.

@Phury
Last active February 23, 2024 20:04
Show Gist options
  • Save Phury/7a425105c8babb5bee631a53d987fe61 to your computer and use it in GitHub Desktop.
Save Phury/7a425105c8babb5bee631a53d987fe61 to your computer and use it in GitHub Desktop.
Export CardMarket tables in TSV (and copies to clipboard)
function mapRow(row) {
return Array.from(row.cells).map(cell => {
if (cell.className.indexOf('amount') > -1) return cell.textContent.replace('x', '');
if (cell.className.indexOf('name') > -1) return cell.textContent;
if (cell.className.indexOf('price') > -1) return cell.textContent;
return null;
})
.filter(parsed => parsed !== null)
.join(' ');
}
function parseTable(id) {
return Array.from(document.getElementById(id).querySelector('tbody').children).map(mapRow).join('\n');
}
function tableIdToTsv(id) {
var tsv = parseTable(id);
return tsv;
}
function cmkTableToTsvClipboard() {
var table = document.getElementsByClassName('product-table')[0];
var tsv = tableIdToTsv(table.id);
//navigator.clipboard.writeText(tsv);
console.log(tsv);
copy(tsv);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment