Skip to content

Instantly share code, notes, and snippets.

@kvanbere
Created January 5, 2018 23:23
Show Gist options
  • Save kvanbere/0eebe59bda67c5fb438a4957917b60cd to your computer and use it in GitHub Desktop.
Save kvanbere/0eebe59bda67c5fb438a4957917b60cd to your computer and use it in GitHub Desktop.
Paste in the terminal with the svg open, then inspector -> view as HTML and copy result out
classMap = {}
var rules = document.styleSheets[0].cssRules // 1. get first stylesheet
for (var j = 0; j < rules.length; j++) { // 2. loop over all rules
var selector = rules[j].selectorText
var csstext = rules[j].cssText
classMap[selector.replace(".", "")] = csstext.split("{")[1].replace("}", "") // 3. save class name and rule text to mapper object
}
document.querySelectorAll("rect,path,polygon,image").forEach(function(item, index) { // 4. loop over all rects
var style = ""
item.classList.forEach(function(className) { // 5. loop over all class names
style += classMap[className] // 6. + 7. get style rules form mapper and concat
})
item.removeAttribute("class") // 8. remove class
item.setAttribute("style", style) // 9. add inline style
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment