X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fgame.js;h=3eb27f27130689013d72437bca18b5c61b40d8bd;hp=40035a5fb256052612eac0e5c8adb827121f5c2b;hb=01ca2adce0ddcf246f184c6d19389262b0f5e6e5;hpb=3ed62725fe47e395793cf952403d61fc9f347eee diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index 40035a5f..3eb27f27 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -334,10 +334,20 @@ Vue.component('my-game', { { elementArray.push( h('div', - { }, + { attrs: { id: "pgn-div" } }, [ + h('a', + { + attrs: { + id: "download", + href: "#", + } + } + ), h('p', { + attrs: { id: "pgn-game" }, + on: { click: this.download }, domProps: { innerHTML: this.vr.getPGN(this.mycolor, this.score, this.fenStart, this.mode) } @@ -470,6 +480,15 @@ Vue.component('my-game', { this.conn.onclose = socketCloseListener; }, methods: { + download: function() { + let content = document.getElementById("pgn-game").innerHTML; + content = content.replace(/
/g, "\n"); + // Prepare and trigger download link + let downloadAnchor = document.getElementById("download"); + downloadAnchor.setAttribute("download", "game.pgn"); + downloadAnchor.href = "data:text/plain;charset=utf-8," + encodeURIComponent(content); + downloadAnchor.click(); + }, endGame: function(score) { this.score = score; let modalBox = document.getElementById("modal-eog");