-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
6 changed files
with
696 additions
and
684 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,17 @@ | ||
export const copyToClipboard = (textToCopy: string) => { | ||
const textarea = document.createElement('textarea') | ||
textarea.setAttribute('readonly', 'readonly') | ||
textarea.value = textToCopy | ||
textarea.style.position = 'fixed' | ||
textarea.style.top = '0' | ||
document.body.insertBefore(textarea, document.body.childNodes[0]) | ||
textarea.focus() | ||
textarea.setSelectionRange(0, textToCopy.length) // 兼容 iOS select() 方法不可用问题。最大复制长度 9999 | ||
if (document.execCommand('copy')) { | ||
document.execCommand('copy') | ||
document.body.removeChild(textarea) | ||
return 0 | ||
} | ||
document.body.removeChild(textarea) | ||
return -1 | ||
} |
Oops, something went wrong.