-
-
Save marcelaraujo/f6c0ccc23256383ec850 to your computer and use it in GitHub Desktop.
This file contains 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
function updateSVG() { | |
var el = document.querySelector('.icon-user'); | |
var style = window.getComputedStyle(el); | |
var uri = style.backgroundImage; | |
var svg64 = uri.replace(/^.+base64,/, "").replace(/\"?\)$/, "") | |
var xml = window.atob(svg64); | |
var hex = '#' + Math.floor(Math.random()*16777215).toString(16); | |
var color = xml.replace(/fill="#[A-Za-z0-9]+"/, 'fill="' + hex + '"'); | |
var color64 = window.btoa(color); | |
var colorUri = "url('data:image/svg+xml;base64," + color64 + "')"; | |
el.style.backgroundImage = colorUri; | |
} | |
document.querySelector('#changeme').onclick = updateSVG; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment