Created
December 28, 2025 16:55
-
-
Save seleb/a11f99aa62c6038afb47217844b8cd46 to your computer and use it in GitHub Desktop.
script for downloading a set of images on a page
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
| (() => { | |
| const SELECTOR = '#container img'; | |
| const NAME = 'prefix_{NUM}.png'; | |
| const elCanvas = document.createElement('canvas'); | |
| const ctx = elCanvas.getContext('2d'); | |
| const a = document.createElement('a'); | |
| function download(elImg, filename) { | |
| elCanvas.width = elImg.naturalWidth; | |
| elCanvas.height = elImg.naturalHeight; | |
| ctx.clearRect(0, 0, elCanvas.width, elCanvas.height); | |
| ctx.drawImage(elImg, 0, 0); | |
| a.href = elCanvas.toDataURL(); | |
| a.download = filename; | |
| a.click(); | |
| } | |
| document.querySelectorAll(SELECTOR).forEach(async (elImg, idx, arr) => { | |
| try { | |
| download(elImg, NAME.replace('{NUM}', idx.toString(10).padStart(arr.length.toString(10).length, '0'))); | |
| return; | |
| } catch (e) { | |
| console.error(e); | |
| } | |
| }); | |
| a.remove(); | |
| elCanvas.remove(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment