Skip to content

Instantly share code, notes, and snippets.

@wilt00
Created February 18, 2022 04:20
Show Gist options
  • Save wilt00/b0da26a0b5ef79d8ec80add43d895a10 to your computer and use it in GitHub Desktop.
Save wilt00/b0da26a0b5ef79d8ec80add43d895a10 to your computer and use it in GitHub Desktop.
diff --git a/posts/morse-codle/morse-codle.js b/posts/morse-codle/morse-codle.js
index b426847..78bc82e 100644
--- a/posts/morse-codle/morse-codle.js
+++ b/posts/morse-codle/morse-codle.js
@@ -150,8 +150,7 @@ function getDayOffset() {
const GAME_NUMBER = getDayOffset();
const STEP = 4;
-function share(event) {
- event.preventDefault();
+function buildShareString() {
// Build results array
var result = '';
for (let i = 0; i < gameState.currentGameGuesses.length; i++) {
@@ -170,13 +169,16 @@ function share(event) {
result += '\n';
}
// Copy results to clipboard
- const stringToCopy =`
+ return `
-- --- .-. ... . -.-. --- -.. .-.. .
Game #${GAME_NUMBER}
${result}`;
+}
- clipboard.writeText(stringToCopy).then(function () {
+function share(event) {
+ event.preventDefault();
+ clipboard.writeText(buildShareString()).then(function () {
alert('Text copied successfully.');
}, function (err) {
alert('There was a problem copying your result.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment