Skip to content

Instantly share code, notes, and snippets.

@leongersen
Created December 10, 2016 11:19
Show Gist options
  • Save leongersen/f6770021413c9a2f200664b1a815c988 to your computer and use it in GitHub Desktop.
Save leongersen/f6770021413c9a2f200664b1a815c988 to your computer and use it in GitHub Desktop.
Quick tool for automatically converting line-separated lists to comma-separated
<!DOCTYPE html>
<html style="height:100%">
<link href="style.css" rel="stylesheet">
<div>
<label>Totaal: <input id="yy" style="width:80px;"></label>
<label><input id="b" type="checkbox">'</label>
<label><input id="c" type="checkbox">"</label>
</div>
<textarea placeholder="paste here!" id="a"></textarea>
<script src="script.js"></script>
</html>
var a = document.getElementById('a');
var b = document.getElementById('b');
var c = document.getElementById('c');
var yy = document.getElementById('yy');
addEventListener('paste', function(){
setTimeout(function(){
var h = b.checked ? '\'' : (c.checked ? '"' : '');
a.value = h + a.value.replace(/(?:\r\n|\r|\n)/g, h + ',' + h) + h;
yy.value = a.value.split(',').reduce(function(ii,jj){return Number(ii)+Number(jj);}, 0);
a.select(); //document.execCommand('copy'); //console.log('copied!');
}, 0);
});
*{margin:0;padding:0;box-sizing:border-box;}
body{padding:15px;height:100%;}
div{height:30px;}
textarea{width:100%;height:calc(100% - 30px);resize:none}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment