summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-08-18 16:48:42 +0200
committerDaniel Weipert <code@drogueronin.de>2023-08-18 16:48:42 +0200
commitf9b00e47e04eac414d892a08136a90833abeefd6 (patch)
tree8b5675eeb877345f081fe98c910ffb7204fd7e10
parent09ee1f7594eb4a3fc9507f05e36bd47cd296e358 (diff)
enabled save to clipboard
-rw-r--r--resources/js/ui.js13
1 files changed, 10 insertions, 3 deletions
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);