Skip to content

Instantly share code, notes, and snippets.

@neo773
Created February 26, 2022 15:41
Show Gist options
  • Save neo773/6220d7b8a6a144010fb3d19672c3ab7e to your computer and use it in GitHub Desktop.
Save neo773/6220d7b8a6a144010fb3d19672c3ab7e to your computer and use it in GitHub Desktop.
Export Pinata Gateway Index as JSON
const dataExport = []
const nameLinks = document.querySelectorAll('a:not(a.ipfs-hash)')
const hashLinks = document.querySelectorAll('a.ipfs-hash')
nameLinks.forEach((link) => {
if (link.innerHTML.includes('jpg')) {
const fileName = link.innerHTML
dataExport.push({
fileName: fileName,
fileHash: null
})
}
})
hashLinks.forEach((link, index) => {
const url = new URL(link.href)
const pathname = url.pathname.replace('/ipfs/', '')
const fileHash = pathname.replace(/\/[^//]+$/, '')
dataExport[index].fileHash = fileHash
})
const download = document.createElement('a')
download.href = URL.createObjectURL(
new Blob([JSON.stringify(dataExport, null, 2)], {
type: 'text/json'
})
)
download.setAttribute('download', 'data-export.json')
document.body.appendChild(download)
download.click()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment