SVG polygons 2 path converter

by PhilQ

HTML

<svg  version="1.1" id="Layer_1" width="658.7480469" height="335.4614258" viewBox="0 0 658.7480469 335.4614258"
	 style="overflow:visible;enable-background:new 0 0 658.7480469 335.4614258;" xml:space="preserve">
<g>
	<polygon points="609.0507813,335.4614258 626.2910156,297.4223633 0,297.4223633 0,335.4614258 
		609.0507813,335.4614258"/>
	<polygon points="79.3647461,284.237793 79.3647461,254.3178711 65.1660156,254.3178711 94.5776367,205.8901367 
		94.5776367,284.237793 149.3442383,284.237793 149.3442383,83.9257813 101.6787109,83.9257813 2.2841797,284.237793 
		79.3647461,284.237793"/>
	<polygon points="165.3222656,284.237793 165.3222656,66.6855469 106.4956055,66.6855469 144.5273438,0 658.2431641,0 
		658.2431641,66.6855469 214.5141602,66.6855469 214.5141602,284.237793 165.3222656,284.237793"/>
	<path d="M232.0073242,284.237793V83.9257813h138.4438477c34.9931641,0,44.3710938,30.4326172,44.3710938,46.402832
		V284.237793h-50.7109375c0,0,0-169.8793945,0-162.2729492c0,7.3500977,2.03125-12.1748047-6.3398438-12.1748047
		c-0.5048828,0-9.6347656,0-9.6347656,0V284.237793h-49.1914063V108.0185547h-17.4931641V284.237793H232.0073242
		L232.0073242,284.237793z"/>
	<polygon points="429.2773438,284.237793 429.2773438,83.9257813 539.0673828,83.9257813 539.0673828,139.9667969 
		464.7763672,139.9667969 464.7763672,155.1791992 539.5761719,155.1791992 539.5761719,208.9360352 465.28125,208.9360352 
		465.28125,222.6254883 539.0673828,222.6254883 539.0673828,284.237793 429.2773438,284.237793"/>
	<polygon points="554.2802734,284.237793 554.2802734,83.9257813 606.2617188,83.9257813 606.2617188,223.1313477 
		658.7480469,223.1313477 633.3925781,284.237793 554.2802734,284.237793"/>
</g>
</svg>
<button id="btn">Convert</button>

JavaScript

$(document).ready(function() {

	$("#btn").click(function() {
	
		$("polygon").each(function(i, el) {
			$el = $(el);
			var points = $el.attr("points").split(/\s+/);
			console.log( points );
			var obj = document.createElementNS('http://www.w3.org/2000/svg', 'path');
			var d = "M";
			for (var c=0, cs=points.length; c < cs; ++c) {
				d = d + (c>0? " L": "") + points[ c ];
			}
			obj.setAttribute("d", d + "z");
			$el.replaceWith( obj );
		});
	
	});

});