-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xdelamotte
committed
Feb 3, 2025
1 parent
044dc25
commit 933d4f1
Showing
4 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,7 @@ GEM | |
PLATFORMS | ||
arm64-darwin-21 | ||
arm64-darwin-22 | ||
arm64-darwin-23 | ||
x86_64-linux | ||
|
||
DEPENDENCIES | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const fallbackCopyTextToClipboard = (text) => { | ||
const textArea = document.createElement("textarea"); | ||
textArea.value = text; | ||
|
||
// Avoid scrolling to bottom | ||
textArea.style.top = "0"; | ||
textArea.style.left = "0"; | ||
textArea.style.position = "fixed"; | ||
|
||
document.body.appendChild(textArea); | ||
textArea.focus(); | ||
textArea.select(); | ||
|
||
try { | ||
const successful = document.execCommand("copy"); | ||
const msg = successful ? "successful" : "unsuccessful"; | ||
console.log("Fallback: Copying text command was " + msg); | ||
} catch (err) { | ||
console.error("Fallback: Oops, unable to copy", err); | ||
} | ||
|
||
document.body.removeChild(textArea); | ||
}; | ||
|
||
const copyTextToClipboard = (text) => { | ||
if (!navigator.clipboard) { | ||
fallbackCopyTextToClipboard(text); | ||
return; | ||
} | ||
navigator.clipboard.writeText(text).then( | ||
() => { | ||
console.log("Async: Copying to clipboard was successful!"); | ||
}, | ||
function (err) { | ||
console.error("Async: Could not copy text: ", err); | ||
}, | ||
); | ||
}; | ||
|
||
const addCopyToClipboardOnButton = (button, getTextToCopy) => { | ||
button.onclick = (e) => { | ||
e.preventDefault(); | ||
copyTextToClipboard(getTextToCopy()); | ||
const original = button.innerHTML; | ||
button.innerHTML = "✅ Copied"; | ||
setTimeout(() => (button.innerHTML = original), 1000); | ||
}; | ||
}; |