Last active
July 24, 2023 15:17
-
-
Save refparo/92c506447939579465b57cd66c5c28d2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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