-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add copy to clipboard for ssh-key pair and webhook url (#203)
- Loading branch information
1 parent
aa2a2a7
commit 53ea80a
Showing
4 changed files
with
70 additions
and
7 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
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,38 @@ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
const copyButton = document.getElementById('copyButton'); | ||
|
||
copyButton.addEventListener('click', function() { | ||
// Get the text to copy from the button's data attribute | ||
const textToCopy = copyButton.getAttribute('data-copy-text'); | ||
|
||
// Check if navigator.clipboard is supported | ||
if (navigator.clipboard && navigator.clipboard.writeText) { | ||
navigator.clipboard.writeText(textToCopy) | ||
.then(() => { | ||
alert('Copied to clipboard using navigator: ' + textToCopy); | ||
}) | ||
.catch(err => { | ||
console.error('Could not copy text with navigator: ', err); | ||
}); | ||
} else { | ||
// Deprecated fallback for older browsers | ||
console.warn('Using deprecated document.execCommand("copy") as a fallback. Update your browser for better clipboard support.'); | ||
|
||
// Fallback using document.execCommand | ||
const tempTextarea = document.createElement('textarea'); | ||
tempTextarea.value = textToCopy; | ||
document.body.appendChild(tempTextarea); | ||
tempTextarea.select(); | ||
|
||
try { | ||
document.execCommand('copy'); | ||
alert('Copied to clipboard (using fallback): ' + textToCopy); | ||
} catch (err) { | ||
console.error('Fallback copy failed: ', err); | ||
} | ||
|
||
// Remove the temporary textarea | ||
document.body.removeChild(tempTextarea); | ||
} | ||
}); | ||
}); |