fix: copy to clipboard on non secure context (no SSL) #521

This commit is contained in:
Andreas 2022-10-17 09:45:21 +02:00 committed by GitHub
parent 5c5d8506ec
commit 058766f617
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -397,7 +397,22 @@ export default {
qbit.setAutoTMM(this.hashes, !this.torrent.auto_tmm)
},
copyToClipBoard(text) {
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text)
} else {
const textArea = document.createElement('textarea')
textArea.value = text
textArea.style.position = 'fixed'
textArea.style.opacity = '0'
document.body.appendChild(textArea)
textArea.select()
try {
document.execCommand('copy')
} catch (err) {
console.error('Unable to copy to clipboard', err)
}
document.body.removeChild(textArea)
}
}
}
}