mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 23:56:42 +08:00
fix
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
// 请求和获取剪切板内容
|
// 请求和获取剪切板内容
|
||||||
export async function getClipboardContent() {
|
export async function getClipboardContent() {
|
||||||
if (navigator.clipboard && window.isSecureContext) {
|
try {
|
||||||
return await navigator.clipboard.readText()
|
return await navigator.clipboard.readText()
|
||||||
}
|
}
|
||||||
else {
|
catch (error) {
|
||||||
|
console.error('Unable to read clipboard using navigator.clipboard:', error)
|
||||||
|
|
||||||
|
// Fallback for older browsers or non-secure context
|
||||||
const input = document.createElement('input')
|
const input = document.createElement('input')
|
||||||
document.body.appendChild(input)
|
document.body.appendChild(input)
|
||||||
input.focus()
|
input.select()
|
||||||
document.execCommand('paste')
|
document.execCommand('paste')
|
||||||
const content = input.value
|
const content = input.value
|
||||||
document.body.removeChild(input)
|
document.body.removeChild(input)
|
||||||
@@ -16,10 +19,13 @@ export async function getClipboardContent() {
|
|||||||
|
|
||||||
// 将内容复制到剪切板,兼容非安全域场景
|
// 将内容复制到剪切板,兼容非安全域场景
|
||||||
export async function copyToClipboard(content: string) {
|
export async function copyToClipboard(content: string) {
|
||||||
if (navigator.clipboard && window.isSecureContext) {
|
try {
|
||||||
await navigator.clipboard.writeText(content)
|
await navigator.clipboard.writeText(content)
|
||||||
}
|
}
|
||||||
else {
|
catch (error) {
|
||||||
|
console.error('Unable to write to clipboard using navigator.clipboard:', error)
|
||||||
|
|
||||||
|
// Fallback for older browsers or non-secure context
|
||||||
const input = document.createElement('input')
|
const input = document.createElement('input')
|
||||||
input.value = content
|
input.value = content
|
||||||
document.body.appendChild(input)
|
document.body.appendChild(input)
|
||||||
|
|||||||
Reference in New Issue
Block a user