Skip to content

Instantly share code, notes, and snippets.

@wevertoum
Last active September 21, 2022 19:30
Show Gist options
  • Save wevertoum/cb02e91d596e7f8fd46f480d4b9a34b2 to your computer and use it in GitHub Desktop.
Save wevertoum/cb02e91d596e7f8fd46f480d4b9a34b2 to your computer and use it in GitHub Desktop.
const svg = document.querySelector("#detail > div > div > div > div > div > div > svg");
const svg2 = document.querySelector("#detail > div > div > section > div > div > div > div > div > img");
const getOuterHTML = () => {
const html = svg !== null ? svg : svg2
return html
}
const downloadSvg = () => {
const svgData = getOuterHTML();
const svgBlob = new Blob([svgData.outerHTML], {type:"image/svg+xml;charset=utf-8"});
const svgUrl = URL.createObjectURL(svgBlob);
const downloadLink = document.createElement("a");
downloadLink.href = svgUrl
downloadLink.download = "image.svg"
document.body.appendChild(downloadLink);
downloadLink.click()
document.body.removeChild(downloadLink);
}
downloadSvg();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment