Fix Rapids
by kthornbloom
HTML
Original
<textarea name="" id="original" cols="30" rows="10">
X40 Y50
Z10
X20 Y20
Z-2
X20 Y30
</textarea>
Z Clearance Height: <input type="number" value="10" id="zHeight">
<button>Add Rapids</button>
<br><br>
Converted
<textarea name="" id="converted" cols="30" rows="10">
</textarea>
<!--
Convert To:
X40 Y50
G0 Z10
X20 Y20
G1 Z-2
X20 Y30
-->
CSS
body {
font-family: sans-serif;
}
textarea {
width: 100%;
margin: 5px 0;
}
button {
margin-bottom: 15px;
}
JavaScript
// Run on page load
addRapids();
// Run on click
document.querySelector('button').addEventListener('click', function(e) {
addRapids();
});
function addRapids(){
var txtArea = document.getElementById('original'),
resultArea = document.getElementById('original'),
originalLines = txtArea.textContent.split('\n'),
i,
zHeight = document.getElementById('zHeight');
converted = '';
for (i = 0; i < originalLines.length; i++) {
// DO THE REGEXING
converted += originalLines[i];
converted += '\r\n';
$('#converted').val(converted);
}
}