From f9b00e47e04eac414d892a08136a90833abeefd6 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Fri, 18 Aug 2023 16:48:42 +0200 Subject: enabled save to clipboard --- resources/js/ui.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'resources/js') diff --git a/resources/js/ui.js b/resources/js/ui.js index 455e785..b80ff6f 100644 --- a/resources/js/ui.js +++ b/resources/js/ui.js @@ -699,9 +699,16 @@ const UI = { const popup = UI.createPopup(); const dialog = UI.createTemplate(Template.dialogSave); - dialog.querySelector('[data-template-slot="saveData"]').value = Game.save(); - dialog.querySelector('[data-template-slot="saveClipboard"]').addEventListener('click', () => { - alert('Saved to clipboard!'); + const saveData = Game.save(); + + dialog.querySelector('[data-template-slot="saveData"]').value = saveData; + dialog.querySelector('[data-template-slot="saveClipboard"]').addEventListener('click', async () => { + if (navigator.clipboard) { + await navigator.clipboard.writeText(saveData); + alert('Saved to clipboard!'); + } else { + alert('ERROR: Browser can\'t copy to clipboard! You have to do it manually.'); + } }); popup.querySelector('.popup').appendChild(dialog); -- cgit v1.2.3