Skip to content

Instantly share code, notes, and snippets.

@KevinGutowski
Last active October 11, 2022 22:30
Show Gist options
  • Save KevinGutowski/2390b8df9e2154b447bf971f079137c6 to your computer and use it in GitHub Desktop.
Save KevinGutowski/2390b8df9e2154b447bf971f079137c6 to your computer and use it in GitHub Desktop.
PKMNCards to CSV
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