diff --git a/README.md b/README.md index 9d435a5..7ea95ca 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ - [x] Empty project from template - [x] Configuration - [x] Generate table -- [ ] Copy table option +- [x] Copy table option - [x] Save last state in cookies - [ ] Other format: raw text - [ ] Other format: SVG diff --git a/index.html b/index.html index 23f1d63..fc08007 100644 --- a/index.html +++ b/index.html @@ -95,7 +95,7 @@

Add more vegetables !

-
 klemek - diff --git a/main.js b/main.js index b2c7344..850df84 100644 --- a/main.js +++ b/main.js @@ -231,6 +231,7 @@ const app = createApp({ mix: 25, }, table: [], + copyTableOverride: null, }; }, computed: { @@ -333,6 +334,7 @@ const app = createApp({ } }, generateData() { + this.table.splice(0, this.table.length); if (this.candidates.length <= 2) { return; } @@ -360,9 +362,21 @@ const app = createApp({ table[table.length - 1][1] = "🥗 SALAD 🥗"; } - this.table.splice(0, this.table.length); this.table.push(...table); }, + async copyTable() { + const csvTable = this.table.map((row) => row.join("\t")).join("\n"); + try { + await navigator.clipboard.writeText(csvTable); + this.copyTableOverride = "Table Copied"; + } catch (error) { + console.error(error.message); + this.copyTableOverride = "Error"; + } + setTimeout(() => { + this.copyTableOverride = null; + }, 1000); + }, }, });