Created
February 26, 2022 15:41
-
-
Save neo773/6220d7b8a6a144010fb3d19672c3ab7e to your computer and use it in GitHub Desktop.
Export Pinata Gateway Index as JSON
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
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