Created
July 28, 2023 14:18
-
-
Save itsmikita/24227eacce8b615c47a4284bdfa1ec6a to your computer and use it in GitHub Desktop.
Find and download inline SVG 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
// @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