Last active
October 11, 2022 22:30
-
-
Save KevinGutowski/2390b8df9e2154b447bf971f079137c6 to your computer and use it in GitHub Desktop.
PKMNCards to CSV
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
let main = document.getElementById('genesis-content') | |
let headings = main.getElementsByClassName('headings')[0] | |
let headingText = Array.from(headings.children).map(el=>el.innerText.split(":")[0].replace("\n","")).join(',') | |
let article = Array.from(main.getElementsByTagName('article')) | |
let rowTextArray = article.map(el=>{ | |
let columns = Array.from(el.getElementsByClassName('column')) | |
return columns.map(el=>el.innerText.replace('\n',"")).join(',') | |
}) | |
let csvString = headingText + "\n" + rowTextArray.join('\n') | |
var hiddenEl = document.createElement('a') | |
hiddenEl.href = 'data:text/csv;charset=utf-8,' + encodeURI(csvString) | |
hiddenEl.target = '_blank' | |
let searchParam = document.getElementsByClassName('search-form-input')[0].value | |
hiddenEl.download = searchParam + ".csv" | |
hiddenEl.click() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment