diff options
author | pommicket <pommicket@gmail.com> | 2025-09-18 17:26:10 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2025-09-18 17:26:10 -0400 |
commit | 78a5b3973411ef2a0a43fd84644563157efc8624 (patch) | |
tree | 21390e198e3d675f4efb1136982f40b1a5b4d77d /pub/blankplays.js | |
parent | c1394890e11336dec8f4f3e8b3a21fe34228ce18 (diff) |
Copy results to clipboard
Diffstat (limited to 'pub/blankplays.js')
-rw-r--r-- | pub/blankplays.js | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/pub/blankplays.js b/pub/blankplays.js index 2fef2e9..0bf2da1 100644 --- a/pub/blankplays.js +++ b/pub/blankplays.js @@ -250,7 +250,6 @@ function includeSquare(row, col) { return true; } -// TODO : error handling async function loadChallenge(id) { let result = await fetch(`challenges-${lexicon}/${id}.txt`); if (result.status === 404) { @@ -262,6 +261,7 @@ Please e-mail ${EMAIL}`); Try refreshing the page, or clearing your browser's cache for this site. If problem persists, e-mail ${EMAIL}.`); } + // TODO : check format & report error if wrong let body = await result.text(); let lines = body.split('\n'); board = []; @@ -421,7 +421,20 @@ function showSolution() { if (score !== 100); shareText += '\nCan you do better?'; shareText += `\nhttps://blankplays.pommicket.com?lexicon=${lexicon}`; - document.getElementById('share').value = shareText; + let shareElem = document.getElementById('share'); + shareElem.value = shareText; + let shareCopyButton = document.getElementById('share-copy'); + shareCopyButton.addEventListener('click', async function() { + const COPIED = 'Copied to clipboard!'; + if ('clipboard' in navigator) { + await navigator.clipboard.writeText(shareText); + } else { + shareElem.focus(); + shareElem.select(); + document.execCommand('copy'); + } + shareCopyButton.innerText = COPIED; + }); } function startup() { |