Created
June 27, 2022 09:42
-
-
Save garciparedes/34a8adae99d88b817da79f3b07111664 to your computer and use it in GitHub Desktop.
Download all named `canvas` elements as png images.
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 elements = document | |
| .getElementsByTagName("canvas"); | |
| for (let element of elements) { | |
| if (!element.id) { | |
| continue; | |
| } | |
| const image = element | |
| .toDataURL("image/png") | |
| .replace("image/png", "image/octet-stream"); | |
| const a = document | |
| .createElement("a"); | |
| a.href = image; | |
| a.download = `${element.id}.png`; | |
| a.click(); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment