Skip to content

Instantly share code, notes, and snippets.

@junkycoder
Created April 27, 2021 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junkycoder/86b18bb3fc2d90f1b335664fae9aa0a1 to your computer and use it in GitHub Desktop.
Save junkycoder/86b18bb3fc2d90f1b335664fae9aa0a1 to your computer and use it in GitHub Desktop.
Download all svg icons on page
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