Skip to content

Instantly share code, notes, and snippets.

@itsmikita
Created July 28, 2023 14:18
Show Gist options
  • Save itsmikita/24227eacce8b615c47a4284bdfa1ec6a to your computer and use it in GitHub Desktop.
Save itsmikita/24227eacce8b615c47a4284bdfa1ec6a to your computer and use it in GitHub Desktop.
Find and download inline SVG images.
// @url https://t-hamano.github.io/wordpress-icon-list/
let __download_svgs = () => {
const kebaptize = ( t ) => t.split( "" ).map( ( c, x ) => c === c.toUpperCase() ? `${ x != 0 ? "-" : "" }${ c.toLowerCase() }` : c ).join( "" );
let svg, file, a, allow = [ "xmlns", "viewBox" ];
document.querySelectorAll( ".iconlist button" ).forEach( ( btn, x ) => {
a = document.createElement( "a" );
a.innerHTML = btn.innerHTML;
btn.replaceWith( a );
svg = a.querySelector( "svg" );
console.log( x, svg );
svg.getAttributeNames().map( attr =>
allow.includes( attr ) ? attr : svg.removeAttribute( attr )
);
file = new File( [ svg.outerHTML ], `${ kebaptize( a.querySelector( "span" ).textContent ) }.svg`, { type: "image/svg+xml" } );
a.href = URL.createObjectURL( file );
a.download = file.name;
a.click();
} );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment