Created
February 6, 2026 13:15
-
-
Save micartey/d512e300d1da0fa219865ca8570b32cf to your computer and use it in GitHub Desktop.
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
| document.querySelectorAll('img[src$=".svg"]').forEach(async img => { | |
| try { | |
| const response = await fetch(img.src); | |
| const text = await response.text(); | |
| const parser = new DOMParser(); | |
| const doc = parser.parseFromString(text, 'image/svg+xml'); | |
| const svg = doc.documentElement; | |
| // styling | |
| svg.style.userSelect = 'text'; | |
| svg.style.cursor = 'text'; | |
| svg.querySelectorAll('text, tspan').forEach(t => { | |
| t.style.userSelect = 'text'; | |
| t.style.cursor = 'text'; | |
| }); | |
| // Identify if the image is wrapped in a link | |
| const parentLink = img.closest('a'); | |
| const targetToReplace = parentLink ? parentLink : img; | |
| targetToReplace.replaceWith(svg); | |
| } catch (e) { | |
| console.error('Conversion failed:', img.src); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment