ui: 改善 复制到剪贴薄 的用户体验
* 在 Via 浏览器上, writeText 本质上被重写了, 逻辑还是 execCommand copy * 更换 copy 为 cut
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
export default function copyToClipboard(text: string) {
|
export default function copyToClipboard(text: string) {
|
||||||
if (navigator.clipboard)
|
if (!("via" in window) && navigator.clipboard)
|
||||||
return navigator.clipboard.writeText(text)
|
return navigator.clipboard.writeText(text)
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
if (document.hasFocus()) {
|
if (document.hasFocus()) {
|
||||||
@@ -10,7 +10,7 @@ export default function copyToClipboard(text: string) {
|
|||||||
a.style.top = "10px"
|
a.style.top = "10px"
|
||||||
a.value = text
|
a.value = text
|
||||||
a.select()
|
a.select()
|
||||||
document.execCommand("copy", true)
|
document.execCommand("cut", true)
|
||||||
document.body.removeChild(a)
|
document.body.removeChild(a)
|
||||||
res(null)
|
res(null)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user