-
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.
* Implement copy support * Remove unused import
- Loading branch information
Showing
3 changed files
with
46 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const fallbackCopyToClipboard = (url: string) => { | ||
const placeholder = document.createElement("textarea"); | ||
placeholder.value = url; | ||
|
||
// Avoid scrolling to bottom | ||
placeholder.style.top = "0"; | ||
placeholder.style.left = "0"; | ||
placeholder.style.position = "fixed"; | ||
|
||
// Append element, and focus | ||
document.body.appendChild(placeholder); | ||
placeholder.focus(); | ||
placeholder.select(); | ||
|
||
// Finally, remove element after copy | ||
document.body.removeChild(placeholder); | ||
}; | ||
|
||
export const getCurrentUrlAndCopyToClipboard = () => { | ||
const url = window.location.href; | ||
if (!navigator.clipboard) fallbackCopyToClipboard(url); | ||
else navigator.clipboard.writeText(url); | ||
return url; | ||
}; | ||
|
||
export default getCurrentUrlAndCopyToClipboard; |