Created
April 27, 2021 13:34
-
-
Save junkycoder/86b18bb3fc2d90f1b335664fae9aa0a1 to your computer and use it in GitHub Desktop.
Download all svg icons on 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
function download(filename, text, mime = 'image/svg+xml', ext = 'svg') { | |
var element = document.createElement('a'); | |
element.setAttribute('href', `data:${mime};charset=utf-8, ${encodeURIComponent(text)}`); | |
element.setAttribute('download', `${filename}.${ext}`); | |
element.style.display = 'none'; | |
document.body.appendChild(element); | |
element.click(); | |
document.body.removeChild(element); | |
} | |
const containerSelector = 'body'; | |
let index = 0; | |
for (let svg of document.querySelectorAll(`${containerSelector} svg`)) { | |
download(`icon-${index++}`, svg.outerHTML); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment