Last active
February 23, 2024 20:04
-
-
Save Phury/7a425105c8babb5bee631a53d987fe61 to your computer and use it in GitHub Desktop.
Export CardMarket tables in TSV (and copies to clipboard)
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
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