Skip to content

Instantly share code, notes, and snippets.

@refparo
Last active July 24, 2023 15:17
Show Gist options
  • Save refparo/92c506447939579465b57cd66c5c28d2 to your computer and use it in GitHub Desktop.
Save refparo/92c506447939579465b57cd66c5c28d2 to your computer and use it in GitHub Desktop.
// fig: the <figure> element to download
// could be easily used in batch download
// requires CORS errors to be disabled
const dlPhoto = async (fig) => {
const img = fig.querySelector('u > a').href
const res = await (await fetch(img)).text()
const doc = new DOMParser().parseFromString(res, 'text/html')
const photo = doc.querySelector('#submissionImg').src
const blob = await (await fetch(photo)).blob()
const a = document.createElement('a')
const url = window.URL.createObjectURL(blob)
const filename = fig.querySelector('p:first-child > a').textContent + '.jpg'
a.href = url
a.download = filename
document.body.appendChild(a)
a.click()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment