Skip to content

Commit

Permalink
add button to copy result table to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
T1mL3arn committed Feb 19, 2019
1 parent f58cfb4 commit d9e8f73
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,3 +608,17 @@ function _pad(text, length, char, align) {
function _repeat(str, num) {
return new Array(num + 1).join(str);
}

function copyOutputToClipboard() {
const output = $('#output').val();

if (navigator.clipboard) {
navigator.clipboard.writeText(output).catch(e => console.error('Cannot write to clipboard', e));
} else {
const tmp = $('<textarea>');
$('body').append(tmp);
tmp.val(output).select();
document.execCommand('copy');
tmp.remove();
}
}
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ <h2>Output</h2>
<div class="row">
<button class="btn btn-lg btn-primary" onclick="parseTableClick()">Parse <i class="fa fa-table"></i></button>
</div>
<div class="row">
<button class="btn btn-md btn-secondary" onclick="copyOutputToClipboard()" style="margin: 0.5em">Copy <i class="fa fa-copy"></i></button>
</div>
</div>
<div class="col-xs-9">
<div id="outputText" class="row">
Expand Down

0 comments on commit d9e8f73

Please sign in to comment.