mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 23:56:42 +08:00
fix(copy): Mobile compatibility issues
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import copy from 'copy-to-clipboard'
|
||||||
|
|
||||||
// 请求和获取剪贴板内容
|
// 请求和获取剪贴板内容
|
||||||
export async function getClipboardContent() {
|
export async function getClipboardContent() {
|
||||||
if (navigator.clipboard && window.isSecureContext) {
|
if (navigator.clipboard && window.isSecureContext) {
|
||||||
@@ -13,20 +15,10 @@ export async function getClipboardContent() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将内容复制到剪贴板,兼容非安全域场景
|
// 将内容复制到剪贴板
|
||||||
export async function copyToClipboard(content: string) {
|
export async function copyToClipboard(content: string) {
|
||||||
if (navigator.clipboard && window.isSecureContext) {
|
const success = copy(content)
|
||||||
await navigator.clipboard.writeText(content)
|
return success
|
||||||
} else {
|
|
||||||
const input = document.createElement('textarea')
|
|
||||||
input.value = content
|
|
||||||
document.body.appendChild(input)
|
|
||||||
// 阻止事件冒泡到其他元素,确保 focusin 事件只在 textarea 元素上处理,不会影响其他元素
|
|
||||||
input.addEventListener('focusin', e => e.stopPropagation())
|
|
||||||
input.select()
|
|
||||||
document.execCommand('copy')
|
|
||||||
document.body.removeChild(input)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// VAPID公钥转Uint8Array
|
// VAPID公钥转Uint8Array
|
||||||
|
|||||||
Reference in New Issue
Block a user